0👍
✅
My suggestion is to save the default value somewhere else, such as:
<script>
const defaultArr = [true, false, true, false, true, true, true];
export default {
data() {
return {
arr: [...defaultArr]
};
},
methods: {
toggleItem(index) {
this.arr.splice(index, 1, !this.arr[index]);
},
resetState() {
// set the array arr to initial data after some toggleItem() changes
this.arr = [...defaultArr];
},
},
};
</script>
Note the spreading syntax
[...]
is neccessary since you don’t want to mutate the default array.
Source:stackexchange.com