如何對vue中的元件進行點選事件監聽
阿新 • • 發佈:2018-12-12
<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