watch 監聽不生效,還報錯
<!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>
2020-04-22
難道就沒人發現括號匹配不對嗎?computed:{}的右括號將整個watch的內容都包住了……注意IDE里面的左右括號匹配提示。
2020-04-20
不是吧,watch和computed就是在同一級別的啊,你watch里邊的代碼也有問題吧
2020-04-16
檢查后發現watch位置不對,不應該和computed在同一級別的。。。