Answer the question
In order to leave comments, you need to log in
How to get the previous state of an array in watch?
https://codesandbox.io/s/mystifying-meadow-hnovr?f...
We want prevItems to keep the previous value of items. I googled the design that I depicted in the sandbox, but it does not work. I know that I can do this in a method, but this does not suit me, because in a real example, the items array is changed by several different methods at once, and changing the value of prevItems inside each seems like a bad idea.
Answer the question
In order to leave comments, you need to log in
watch: {
cloneItems(old, cur) {
this.prevItems = old;
},
computed: {
cloneItems: () => this.items.slice(),
prev items:
<div v-for="item in items" :key="item">
this.items = [...this.items, Date.now()];
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question