watch三种写法
watch: { // 方式一: 'cityName.name': { handler(newName, oldName) { // ... }, deep: true, immediate: true //立即执行 } //方式二: cityName(newName, oldName){ // ... } //方式三: cityName:{ handler(newName, oldName) { // ... }, } }
方式四:$watch
created(){ const unwatch = this.$watch("cityName",function(){ // ... },{ deep: true, immediate: true })
// unwatch() //一旦变化后就取消监听 }

浙公网安备 33010602011771号