需求:假如現(xiàn)在有個導(dǎo)航鸭栖,第一個有默認(rèn)樣式,其它的點擊誰誰有樣式握巢,而原先有樣式要取消掉
直接上代碼了
<div id="app">
<ul>
<li v-for="(item, index) in items" :class="{'active': isActive == index}" @click="handleActive(index)">{{ item }}</li>
</ul>
</div>
<script>
var app1 = new Vue({
el: "#app1",
data: {
items: ['q','w'],
isActive: 0
},
methods: {
handleActive: function(index) {
this.isActive = index;
}
}
});
</script>