vue.js:634 [Vue warn]: Invalid handler for event “click“: got undefined

it2023-09-04  84

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>
最新回复(0)