<div v-for="(item,index) in arrFilter" :class="{'check':checkIndex===index}" @click="checkIndex=index">
{{item}}
</div>
<div @click="more"></div>
export default {
data: () => {
return {
// 排他默认第 0 个元素
checkIndex: 0,
// 默认限制 arr 条数为 3
limit: 3,
arr: []
}
},
computed: {
// 限制显示 arr 为 limit 值
arrFilter: function () {
return this.arr.slice(0, this.limit)
},
},
methods: {
// 展开或收起 arr
more: function () {
if (this.arr === 3) {
this.limit = this.arr.length
} else {
this.limit = 3
}
}
}
}