如何对vue中的组件进行点击事件监听

 <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-default/index.css">
</head>
<body>
    <div id="app">
        <component :is="name" @click.native="click"></component>
    </div>
    <!-- 先引入 Vue -->
    <script src="https://unpkg.com/vue/dist/vue.js"></script>
    <!-- 引入组件库 -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <script>
        Vue.component('btn', {
            template: '<el-button>按钮</el-button>'
        })

        new Vue({
            el: '#app',
            data: function () {
                return { name: 'btn' }
            },
            methods: {
                click() {
                    console.log('click')
                }
            }
        })
    </script>
</body>
</html>

 @click.native

展开阅读全文

没有更多推荐了,返回首页