如何对vue中的组件进行点击事件监听
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-default/index.css"></head><body><div id="app">
·
<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
更多推荐
已为社区贡献6条内容
所有评论(0)