<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
}
}
}
}