有没有办法将 vue.js 事件附加到现有的 html 元素?
HTML 元素:
<div class="borrow-button">Borrow</div>
<div class="borrow-button">Borrow</div>
<div class="borrow-button">Borrow</div>
我可以以某种方式向此 div 添加 vue.js 事件吗?
$('.borrow-button').each(function(i, obj) {
//how to append for example onclick event to this divs? (onclick="borrow")
});
最佳答案
我目前不知道有任何 vue 方法可以做到这一点。但由于 jsgrid 使用 jquery,因此您可以使用 event handler attachment它来绑定(bind)vue方法。
这是一个例子:
var demo = new Vue({
el: '#demo',
data: function(){
return {
};
},
methods:{
myMethod () {
alert('Do whatever you wanns do')
}
},
mounted () {
$("#myBtn").on('click', this.myMethod);
}
})
您可以检查此代码是否正常工作 here .
关于javascript - 如何将 vue.js 事件附加到现有 html 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41183388/