watch 監(jiān)聽(tīng)不生效,還報(bào)錯(cuò)
<!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
難道就沒(méi)人發(fā)現(xiàn)括號(hào)匹配不對(duì)嗎?computed:{}的右括號(hào)將整個(gè)watch的內(nèi)容都包住了……注意IDE里面的左右括號(hào)匹配提示。
2020-04-20
不是吧,watch和computed就是在同一級(jí)別的啊,你watch里邊的代碼也有問(wèn)題吧
2020-04-16
檢查后發(fā)現(xiàn)watch位置不對(duì),不應(yīng)該和computed在同一級(jí)別的。。。