<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="js/vue.js"> </script>
</head>
<body>
<div id="root">
<input placeholder="姓氏" v-model="firstname" />
<input placeholder="名字" v-model="lastname" />
{{fullName}}
{{count}}
</div>
<script>
new Vue({
el:"#root",
data:{
firstname:'',
lastname:'',
count:0
},
computed:{
fullName:function(){
//if(this.firstname!=''&&this.lastname!=''){
return this.firstname+'·'+this.lastname
// }
},
watch:{
firstname:function(){
this.count= count+1
return count
},
lastname:function(){
this.count= count+1
return count
}
}
}
})
</script>
</body>
</html>
难道就没人发现括号匹配不对吗?computed:{}的右括号将整个watch的内容都包住了……注意IDE里面的左右括号匹配提示。
不是吧,watch和computed就是在同一级别的啊,你watch里边的代码也有问题吧
检查后发现watch位置不对,不应该和computed在同一级别的。。。