javascript - 我在vue中的v-for里绑定事件报错?
本文介绍了javascript - 我在vue中的v-for里绑定事件报错?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
我在v-for里面循环生成route-link,想给他绑定一个事件,结果报错说事件未定义,下面是我的代码
<ul class="card-list">
<li v-for="(url, index) in urls">
<router-link class="linkTo" :to="'/Page' + (index + 1)">
<img @click="total(index)" class="cardWidth" :src="url" alt="">
</router-link>
</li>
</ul>
method: {
total: function (index) {
console.log(index)
}
}
报错信息:
Property or method "total" is not defined on the instance but referenced during render. Make sure to declare reactive data properties in the data option.
Uncaught TypeError: _vm.total is not a function
解决方案
是 methods
http://vuejs.org/v2/api/#methods
这篇关于javascript - 我在vue中的v-for里绑定事件报错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文