Vue学习笔记5———监听属性

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script src="js/Vue.js"></script>
	</head>
	<body>
		<div id='app'>
			<input v-model="first" />
			<input v-model="last" />
			<p>{{name}}</p>
			
		</div>
		<script>
			var vm = new Vue({
				el:'#app',
				data:{
					first:'Hello',
					last:'Vue!',
					name:'Hello Vue!'
				},
				watch:{
					first:function(value){
						this.name = value + ' ' + this.last
					}
				}
			});
			vm.$watch('last',function(value){
				this.name = this.first + ' '+ value
			})
		</script>
	</body>
</html>

猜你喜欢

转载自blog.csdn.net/progammer10086/article/details/85833784