一、单选:
思路:当点击的索引值 == v-for循环的索引值时,给你那个li添加选中样式
1.html
<ul class="box">
<li v-for="c,index of cities" :class="{checked:index==n}" @click="changeList(index)">{{c}}</li>
</ul>
2.js
var app = new Vue({
el : ".box",
data : {
cities : ["上海","北京","广州","重庆","西安"],
n : 0
},
methods :{
changeList(index){
this.n = index;//this指向app
}
}
})
3
