在導航串列中。我在單擊時添加了一個類,當我再次單擊時它會起作用。它將類添加到串列的所有專案中。我只想在 Click 上一次激活一個專案。另外,我點擊了兩個動作(滾動然后添加一個類)
<b-navbar class="d-flex flex-column align-items-start>
<b-navbar-brand tag="h3" hljs-number">0">List Index</b-navbar-brand>
<b-navbar-nav v-for="(linkItem, index) in linkItems" :key="index">
<b-nav-item :hljs-attr">active: isActive }" hljs-number">2" @click="scrollTo(`${linkItem.id}`), (isActive = !isActive)">
{{ linkItem.title }}
</b-nav-item>
</b-navbar-nav>
</b-navbar>
方法是
data() {
return {
isActive: false,
linkContent: [] as any
};
},
scrollTo { This is working fine},
activeLink() {
this.isActive = true;
}
}
});
我需要幫助使該類僅適用于活動元素。
謝謝
uj5u.com熱心網友回復:
只需將索引發送到 isActive 狀態。
:class="{ 'active': isActive === index }"
點擊你必須提供它的索引
@click="scrollTo(`${linkItem.id}`), (isActive = index)"
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/464794.html
標籤:javascript Vue.js 班级 切换 添加
