template代碼是<div class="news_title" v-on:click="news_title" >
<ul>
<li class="news_active" type1="0">籃球</li>
<li type1="1">中超</li>
<li type1="2">英超</li>
<li type1="3">西甲</li>
<li type1="4">德甲</li>
<li type1="5">意甲</li>
<li type1="6">幸運(yùn)球場(chǎng)</li>
</ul></div>原jq代碼是:$(".news_title").on("click",'li',function(){
$(".news_title li").removeClass("news_active");
$(this).addClass("news_active"); var type=$(this).attr("type1");
});請(qǐng)教下怎么遷移這個(gè)jq到vue上做點(diǎn)擊事件呢?即點(diǎn)擊li添加類(lèi)名,兄弟去除類(lèi)名.看網(wǎng)上的方法都是要做for循環(huán),請(qǐng)問(wèn)下有不做for循環(huán)就能實(shí)現(xiàn)的方法嗎?前提不要太復(fù)雜,蟹蟹
1 回答

呼如林
TA貢獻(xiàn)1798條經(jīng)驗(yàn) 獲得超3個(gè)贊
<li v-for="(item, index) in list" :class="{ 'active': activeIndex === index}" @click="activate(index)">籃球</li> data(){ return { activeIndex: 0 } }, methods: { activate(index){ this.activeIndex = index } }
添加回答
舉報(bào)
0/150
提交
取消