本文介绍了如何单击整个 vuejs 组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
I have component
and i want run method after click
<my-component @click="showOtherDiv"></my-component>
i have this method on main app methods
var app = new Vue({
el: '#app',
data: {},
methods: {
showOtherDiv : function(){
alert('Some message');
}
}
});
but seems like "click" not works on full component
解决方案
Register your component, and declare the handler method inside:
Vue.component('my-component', { // ... methods: { showOtherDiv : function(){ alert('Some message'); } } });
Add the
.native
modifier to the event name:<my-component @click.native="showOtherDiv"></my-component>
From the docs:
这篇关于如何单击整个 vuejs 组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!