vue 列表实现单个点击显示隐藏
<div id="app"> <div v-for="item in items"> <toggle-list-item :item="item"></toggle-list-item> </div&am
<div id="app">
<div v-for="item in items">
<toggle-list-item :item="item"></toggle-list-item>
</div>
</div>
<template id="list-item">
<div>
<div>
{{item.text}}
</div>
<button @click="toggle()">show</button>
<div v-show="isActive" class="item-desc">
{{item.desc}}
</div>
</div>
</template>
#js
Vue.component('toggle-list-item', {
template: '#list-item',
props: ['item'],
methods: {
toggle() {
this.isActive = !this.isActive;
}
},
data() {
return {
isActive: false
}
},
})
new Vue({
el: '#app',
data: {
items: [{
text: 'foo',
desc: 'foo desc'
}, {
text: 'bar',
desc: 'bar desc'
}, {
text: 'baz',
desc: 'baz desc'
}]
}
});
更多推荐
所有评论(0)