<div id="app">
{{total}}
</div>
<script>
var vm = new Vue({
el: "#app",
data() {
return {
firstName: 1,
lastName: 2,
total: 3
}
},
/* 监听data中的值,只要值改变函数就会触发 */
watch: {
firstName() {
this.total = this.firstName + this.lastName
},
lastName() {
this.total = this.firstName + this.lastName
}
}
})
</script>