最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Vue3實(shí)現(xiàn)點(diǎn)擊按鈕實(shí)現(xiàn)文字變色功能

 更新時(shí)間:2024年07月01日 09:36:45   作者:FOREVER-Q  
這篇文章主要介紹了使用Vue3實(shí)現(xiàn)點(diǎn)擊按鈕實(shí)現(xiàn)文字變色功能,文中通過代碼示例給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作有一定的幫助,需要的朋友可以參考下

1.動(dòng)態(tài)樣式實(shí)現(xiàn)

1.1核心代碼解釋:

  • class="power-station-perspective-item-text"

    • 為這個(gè) span 元素添加了一個(gè) CSS 類,以便對(duì)其樣式進(jìn)行定義。
  • @click="clickItem(item.id)"

    • 這是一個(gè) Vue 事件綁定。當(dāng)用戶點(diǎn)擊這個(gè) span 元素時(shí),會(huì)觸發(fā) clickItem 方法,并將 item.id 作為參數(shù)傳遞給該方法。這用于記錄用戶點(diǎn)擊了哪個(gè)項(xiàng)目。
  • :style="{ color: isChecked(item.id) ? '#cc7e17' : '' }"

    • 這是一個(gè) Vue 動(dòng)態(tài)綁定的內(nèi)聯(lián)樣式。
    • isChecked(item.id) 會(huì)檢查當(dāng)前項(xiàng)目是否被選中(即 checkedItem.value 是否等于 item.id)。
    • 如果 isChecked(item.id) 返回 true,則 color 樣式會(huì)被設(shè)置為 '#cc7e17'(一種顏色值);否則,color 樣式為空字符串,表示不改變顏色。
  • {{ item.title }}

    • 這是一個(gè) Vue 插值語法,用于顯示每個(gè)項(xiàng)目的標(biāo)題文本。
     <span
            class="power-station-perspective-item-text"
            @click="clickItem(item.id)"
            :style="{ color: isChecked(item.id) ? '#cc7e17' : '' }">
          {{ item.title }}
        </span>

1.2源代碼

<template>
  <div class="power-station-perspective">
    <div class="flow-chart-container-item">
      <div class="power-station-perspective-title flow-chart-container-item-parent">
        {{ title }}
      </div>
      <div v-for="item in buttonGroupsArr"
          :key="item.id"
          class="power-station-perspective-item flow-chart-container-item location"
      >
        <span
            class="power-station-perspective-item-text"
            @click="clickItem(item.id)"
            :style="{ color: isChecked(item.id) ? '#cc7e17' : '' }">
          {{ item.title }}
        </span>
      </div>
    </div>
  </div>
</template>
 
<script setup>
import {ref, onMounted} from "vue";
 
const title = ref("菜單項(xiàng)");
const buttonGroupsArr = ref([
  {title: "按鈕1", id: 0},
  {title: "按鈕2", id: 1},
  {title: "按鈕3", id: 2},
  {title: "按鈕4", id: 3},
  {title: "按鈕5", id: 4},
]);
 
const checkedItem = ref(0);
 
const isChecked = (param) => {
  return checkedItem.value === param;
};
 
const clickItem = (param) => {
  checkedItem.value = param;
};
 
onMounted(() => {
 
});
</script>
 
<style scoped>
.power-station-perspective{
  width: 200px;
}
.flow-chart-container-item-parent {
  width: 100%;
  background: linear-gradient(90deg, rgba(0, 136, 234, 0.84) 0%,rgba(31, 38, 83, 0.85) 101.82%);
}
 
.flow-chart-container-item {
  display: grid;
  text-align: center;
  padding: 3px 5px 3px 3px;
  margin-bottom: 3px;
  align-items: center;
}
 
.power-station-perspective-item {
  background: rgba(0, 46, 79, 0.5);
}
 
.location {
  cursor: pointer;
}
 
.power-station-perspective-item-text {
  margin: 0 auto;
  cursor: pointer;
}
 
.power-station-perspective-title {
  margin-bottom: 3px;
}
</style>

2.動(dòng)態(tài)類名

 2.1核心代碼解釋

說明:

  • :class 綁定:

    • :class 是 Vue 提供的一個(gè)特性,用于綁定動(dòng)態(tài)類名。
    • 在這里,:class 綁定了一個(gè)數(shù)組,其中包含了兩個(gè)元素。
  • 數(shù)組語法:

    • 數(shù)組的第一個(gè)元素是 'power-station-perspective-item-text'
      • 這意味著每個(gè) span 元素都會(huì)始終應(yīng)用這個(gè)基礎(chǔ)類,確?;緲邮浇y(tǒng)一。
    • 數(shù)組的第二個(gè)元素是一個(gè)對(duì)象:
      • { 'active-power-station-perspective-item-text': isChecked(item.id) }
      • 這個(gè)對(duì)象的鍵是 'active-power-station-perspective-item-text',值是一個(gè)布爾表達(dá)式 isChecked(item.id)
      • 如果 isChecked(item.id) 返回 true,則 active-power-station-perspective-item-text 類會(huì)被應(yīng)用到 span 元素上;否則,不會(huì)應(yīng)用。
 :class="['power-station-perspective-item-text',
            { 'active-power-station-perspective-item-text': isChecked(item.id) }
          ]">

 2.2源代碼

<template>
  <div class="power-station-perspective">
    <div class="flow-chart-container-item">
      <div class="power-station-perspective-title flow-chart-container-item-parent">
        {{ title }}
      </div>
      <div v-for="item in buttonGroupsArr"
          :key="item.id"
          class="power-station-perspective-item flow-chart-container-item location"
      >
        <span
            class="power-station-perspective-item-text"
            @click="clickItem(item.id)"
            :class="[
            'power-station-perspective-item-text',
            { 'active-power-station-perspective-item-text': isChecked(item.id) }
          ]">
          {{ item.title }}
        </span>
      </div>
    </div>
  </div>
</template>
 
<script setup>
import {ref, onMounted} from "vue";
 
const title = ref("菜單項(xiàng)");
const buttonGroupsArr = ref([
  {title: "按鈕1", id: 0},
  {title: "按鈕2", id: 1},
  {title: "按鈕3", id: 2},
  {title: "按鈕4", id: 3},
  {title: "按鈕5", id: 4},
]);
 
const checkedItem = ref(0);
 
const isChecked = (param) => {
  return checkedItem.value === param;
};
 
const clickItem = (param) => {
  checkedItem.value = param;
};
 
onMounted(() => {
 
});
</script>
 
<style scoped>
.power-station-perspective{
  width: 200px;
}
.flow-chart-container-item-parent {
  width: 100%;
  background: linear-gradient(90deg, rgba(0, 136, 234, 0.84) 0%,rgba(31, 38, 83, 0.85) 101.82%);
}
 
.flow-chart-container-item {
  display: grid;
  text-align: center;
  padding: 3px 5px 3px 3px;
  margin-bottom: 3px;
  align-items: center;
}
 
.power-station-perspective-item {
  background: rgba(0, 46, 79, 0.5);
}
 
.location {
  cursor: pointer;
}
 
.power-station-perspective-item-text {
  margin: 0 auto;
  cursor: pointer;
}
.active-power-station-perspective-item-text{
  color: #cc7e17;
}
.power-station-perspective-title {
  margin-bottom: 3px;
}
</style>

3.實(shí)現(xiàn)效果

到此這篇關(guān)于Vue3實(shí)現(xiàn)點(diǎn)擊按鈕實(shí)現(xiàn)文字變色功能的文章就介紹到這了,更多相關(guān)Vue3點(diǎn)擊按鈕文字變色內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Element中table組件(el-table)右側(cè)滾動(dòng)條空白占位處理

    Element中table組件(el-table)右側(cè)滾動(dòng)條空白占位處理

    當(dāng)我設(shè)置了max-height,就會(huì)在表格右側(cè)出現(xiàn)一列空白的占位,本文主要介紹了Element中table組件(el-table)右側(cè)滾動(dòng)條空白占位處理,感興趣的可以了解一下
    2023-09-09
  • 解決Vue項(xiàng)目中Emitted value instead of an instance of Error問題

    解決Vue項(xiàng)目中Emitted value instead of an 

    這篇文章主要介紹了解決Vue項(xiàng)目中Emitted value instead of an instance of Error問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-11-11
  • vue3中使用props和emits并指定其類型與默認(rèn)值

    vue3中使用props和emits并指定其類型與默認(rèn)值

    props是Vue3中的一個(gè)重要概念,它允許我們將數(shù)據(jù)從父組件傳遞到子組件,下面這篇文章主要給大家介紹了關(guān)于vue3中使用props和emits并指定其類型與默認(rèn)值的相關(guān)資料,需要的朋友可以參考下
    2023-04-04
  • vue中路由跳轉(zhuǎn)不計(jì)入history的操作

    vue中路由跳轉(zhuǎn)不計(jì)入history的操作

    這篇文章主要介紹了vue中路由跳轉(zhuǎn)不計(jì)入history的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2020-09-09
  • 深入理解vue3中的reactive()

    深入理解vue3中的reactive()

    本文主要介紹了深入理解vue3中的reactive(),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-02-02
  • vue項(xiàng)目中頁面跳轉(zhuǎn)傳參的方法總結(jié)

    vue項(xiàng)目中頁面跳轉(zhuǎn)傳參的方法總結(jié)

    在Vue項(xiàng)目中,你可以使用路由(vue-router)來實(shí)現(xiàn)頁面跳轉(zhuǎn)并傳遞參數(shù),這篇文章主要為大家整理了一些常用的方法,感興趣的小伙伴可以學(xué)習(xí)一下
    2023-11-11
  • 深入理解vue中的$set

    深入理解vue中的$set

    這篇文章主要介紹了深入理解vue中的$set,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-06-06
  • 基于Vue2.0+ElementUI實(shí)現(xiàn)表格翻頁功能

    基于Vue2.0+ElementUI實(shí)現(xiàn)表格翻頁功能

    Element UI 是一套采用 Vue 2.0 作為基礎(chǔ)框架實(shí)現(xiàn)的組件庫,它面向企業(yè)級(jí)的后臺(tái)應(yīng)用,能夠幫助你快速地搭建網(wǎng)站,極大地減少研發(fā)的人力與時(shí)間成本。這篇文章主要介紹了Vue2.0+ElementUI實(shí)現(xiàn)表格翻頁功能,需要的朋友可以參考下
    2017-10-10
  • vue+iview tabs context-menu 彈出框修改樣式的方法

    vue+iview tabs context-menu 彈出框修改樣式的方法

    今天遇到一個(gè)需求說頁面頂部的菜單右鍵彈出框離得有點(diǎn)遠(yuǎn),需要我們做調(diào)整,下面小編給大家分享下vue+iview tabs context-menu 彈出框修改樣式的方法,感興趣的朋友跟隨小編一起看看吧
    2024-06-06
  • vue-music 使用better-scroll遇到輪播圖不能自動(dòng)輪播問題

    vue-music 使用better-scroll遇到輪播圖不能自動(dòng)輪播問題

    根據(jù)vue-music視頻中slider組建的使用,當(dāng)安裝新版本的better-scroll,輪播組件,不能正常輪播。如何解決這個(gè)問題呢,下面小編給大家?guī)砹藇ue-music 使用better-scroll遇到輪播圖不能自動(dòng)輪播問題,感興趣的朋友一起看看吧
    2018-12-12

最新評(píng)論

高邮市| 张家港市| 商南县| 高邮市| 冷水江市| 阿坝县| 天全县| 长岭县| 密云县| 新乡县| 阿尔山市| 旬邑县| 日照市| 喀喇沁旗| 攀枝花市| 进贤县| 铜川市| 莱阳市| 雅江县| 房山区| 吴忠市| 南召县| 和静县| 武功县| 民和| 莫力| 巍山| 寿阳县| 若羌县| 汝阳县| 磐安县| 成武县| 邓州市| 瑞安市| 淄博市| 明光市| 陵川县| 仲巴县| 江山市| 花垣县| 汉中市|