如何点击整个vuejs组件

How to click on whole vuejs component

我有组件

点击后我想要 运行 方法

<my-component @click="showOtherDiv"></my-component>

我在主要的应用程序方法上有这个方法

var app = new Vue({
    el: '#app',

    data: {},

    methods: {
        showOtherDiv : function(){
            alert('Some message');
        }
    }
});

但似乎 "click" 不适用于完整组件

  1. 注册您的组件,并在其中声明处理程序方法:

    Vue.component('my-component', {
        // ...
        methods: {
            showOtherDiv : function(){
                alert('Some message');
            }
        }
    });
    
  2. 在事件名称中添加.native修饰符:

    <my-component @click.native="showOtherDiv"></my-component>
    

    来自the docs

    Binding Native Events to Components

    […] when you want to listen for a native event on the root element of a component […] you can use the .native modifier for v-on.