Vuejs get old value when on change event

后端 未结 6 1371
耶瑟儿~
耶瑟儿~ 2020-12-14 07:43

Please refer to my snippet below. How can I get the old value of the changed model, in this case is the age in vuejs?

6条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-14 08:20

    It may be too late. This worked for me as long as the function name inside the watch object is named as the variable which is watched. It only watches the specific variable.

    watch:{
       items: function(newVal, oldVal){
          console.log("New value: "+ newVal + ", Old value: " + oldVal);
       },
       other_variable: function(newVal, oldVal){
          console.log("New value: "+ newVal + ", Old value: " + oldVal);
       }
    }
    

提交回复
热议问题