Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.6k views
in Technique[技术] by (71.8m points)

vue点击标签给一个class出现的问题,请各位给愚弟看一下

我目前颜色和尺寸两个属性是是一下子遍历出来的导致,点击给一个样式只能6个中选一个,我想啊,颜色尺寸个选一个,有啥思路不,各位老哥
image.png

<div class="skin">
    <div v-for="(item,index) in configSpec">
        <div class="clear"></div>
        <div class="type">{{item.name}}:</div>
        <ul>
            <li v-for="(i,index) in item.list" :class='{active:currentBtn == i}' @click="checkBtn(i)">{{i}}</li>
        </ul>
    </div>
</div>
    
checkBtn(data){
    console.log(data);
    this.currentBtn === data
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

无非就是找6个中的唯一值

<div class="skin">
    <div v-for="(item,index) in configSpec">
        <div class="clear"></div>
        <div class="type">{{item.name}}:</div>
        <ul>
            <li v-for="(i,index1) in item.list" :class='{active:currentBtn === `${index}${index1}`}' @click="checkBtn(`${index}${index1}`)">{{i}}</li>
        </ul>
    </div>
</div>
    
checkBtn(data){
    console.log(data);
    this.currentBtn === data
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...