<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>计算属性与监听器</title>
<script src="./vue.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<div id="root">
姓:<input v-model="firstName" />
名:<input v-model="lastName" />
<div id="">
{{fullName}}
</div>
<div id="">
{{count}}
</div>
</div>
<script type="text/javascript">
new Vue({
el:"#root",
data:{
firstName:'',
lastName:'',
count: 0
},
computed:{ //计算属性
fullName:function(){
return this.firstName + ' ' + this.lastName
}
},
watch:{ //侦听器
// firstName:function(){
// this.count++
// },
// lastName:function(){
// this.count++
// }
fullName:function(){
this.count++
}
}
})
</script>
</body>
</html>
小仙女般的张小琦 发布了60 篇原创文章 · 获赞 2 · 访问量 2028 私信 关注