如下所示:
<template> <div> <div v-for="(list,index) in siYuan" class="aa" :class="{ red:changeRed == index}" @click="change(index)">{{list.a}}</div> </div></template> <script>export default { data(){ return{ siYuan:[ {"a":"田"}, {"a":"心"}, {"a":"水"}, {"a":"原"} ], changeRed:-1 } }, methods:{ change(index){ this.changeRed = index; } } }</script> <style> .aa{ cursor: pointer; } .red{ color: red; }</style>以上這篇Vue點(diǎn)擊切換顏色的方法就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持錯(cuò)新站長(zhǎng)站。
新聞熱點(diǎn)
疑難解答
圖片精選