vue.js:634 [Vue warn]: Invalid handler for event “click“: got undefined
vue.js:634 [Vue warn]: Invalid handler for event “click”: got undefinedVue运行报错,记录一下原因。报错代码如下HTML<div id="app"><button type="button" @click="clickCount">You have click me {{count}} times<
·
vue.js:634 [Vue warn]: Invalid handler for event “click”: got undefined
Vue运行报错,记录一下原因。
报错代码如下
HTML
<div id="app">
<button type="button" @click="clickCount">You have click me {{count}} times</button>
<button type="button" @click="clickCount2">You have click me {{count}} times</button>
</div>
JavaScript
var app = new Vue({
el:'#app',
data:{
count:0
},
computed:{
clickCount:function(){
this.count ++;
}
},
methods:{
clickCount2:function(){
// alert("click me ");
this.count ++;
}
}
})
原因
click调用函数与计算属性时应带上括号()
<div id="app">
<button type="button" @click="clickCount()">You have click me {{count}} times</button>
<button type="button" @click="clickCount2()">You have click me {{count}} times</button>
</div>
更多推荐
已为社区贡献3条内容
所有评论(0)