The newVal and oldVal returned by the watch array in vue are the same?

data() {
    return {
      colorlist: [
        {
          color: "-sharp333333",
          ftcolor: "-sharpffffff",
          name: "1"
        },
        {
          color: "-sharp55CD31",
          ftcolor: "-sharpffffff",
          name: "2"
        },
        {
          color: "-sharp31ADCD",
          ftcolor: "-sharpffffff",
          name: "3"
        }
      ]
    }
  },
  watch: {
    colorlist: {
      handler: function(val, oldVal) {
        console.log(val, oldVal)
      },
      deep: true
    }
  }

I changed the color of the third one to red. Console output result:

shouldn"t the color of the third oldVal be-sharp31ADCD?

Apr.11,2021

means something like this: when you print an array or an object, the value is taken by reference. When you change the array, the printed value naturally changes


.

look at document

Menu