1.首先在data里面去定义
data () {
const showList = [0, 1, 2, 3, 4, 5]
return {
showList
}
}
2.
switchBox (boxIndex) {
let index = this.showList.indexOf(boxIndex)
if (index >= 0) {
this.showList.splice(index, 1)
} else {
this.showList.push(boxIndex)
}
},
这种写法真的很棒的,同事写的