Vue

Vue

对象属性的深度监听

# 监听userInput对象的year属性和month属性
new Vue({
	el: '#app',
	data: {
		userInput: {
			year: '',
			month: ''
		}
	},
	watch: {
		//方式一
		'userInput.year': {
			handler(newYear, oldYear) {
				console.log(newYear, oldYear)
			},
			deep: true,
			immediate: true
		},
		//方式二
		'userInput.month': (newV, oldV) => {
			console.log(newV, oldV);
		}
	},
});
posted @ 2023-06-14 09:34  谭五月  阅读(14)  评论(0)    收藏  举报