Vuejs 计算属性和监听器
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Event Bind</title>
<script src="./vue.js"></script>
</head>
<body>
<div id="root">
First Name: <input type="text" v-model="firstName" />
Last Name: <input type="text" v-model="lastName" />
<div>
Full Name : {{fullname}}
</div>
<div>
<h2>{{changeTime}}</h2>
</div>
</div>
<script>
new Vue(
{
el: root,
data: {
firstName: '',
lastName: '',
changeTime: 0
},
methods: {
},
computed: {
fullname: function () {
return this.firstName + ' ' + this.lastName;
}
},
watch: {
fullname: function () {
this.changeTime++;
}
}
}
)
</script>
</body>
</html>
页:
[1]