C
C
codharma2018-05-25 21:21:33
Vue.js
codharma, 2018-05-25 21:21:33

Why doesn't the watcher return the old value?

According to the documentation, when using watchit, it is possible to get the old, previous data value. But both are the same for me. What is the point? https://codepen.io/dubx/pen/zjVQNv

watch: {
    array: function (o, n) {
      this.oldData = o
      this.newData = n
    }
  }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
lavezzi1, 2018-05-25
@codharma

Off. documentation says:

Note: when mutating (rather than replacing) an Object or an Array, the old value will be the same as new value because they reference the same Object/Array. Vue doesn't keep a copy of the pre-mutate value.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question