I just want to know how to do this vue.js, right now I can switch the class active
to one element, when I click on another element, the class active
is still displayed in the previous element, here is my setting:
FileOne.vue (parent component)
// Say that I have 5 Items I am rendering here:
<template>
<ul v-for="item in items">
<my-list-item :item-title="article.title"
:item-content="article.content"> </my-list-item>
</ul>
</template>
<script>
import Items from './FileTwo'
export default {}
</script>
fileTwo.vue (child components)
// When I click each Item the `active` class should be applied to the current Item and removed from previous item:
<template>
<li :class="{'active': isRowActive}" @click.stop="toggleRowActive">
<h1>{{articleTitle}}</h1>
<p>{{itemContent}}</p>
</li>
</template>
<script>
export default {
name: 'my-list-item',
data: function () {
return {
isRowActive: false,
}
},
props: {
articleTitle: String,
articleContent: String,
},
toggleRowFn() {
this.isRowActive = !this.isRowActive;
this.showBtnReadContent = true;
},
}
</script>
source
share