The first way to write the execution method]; 2. How to call method."/> The first way to write the execution method]; 2. How to call method.">
Home > Article > Web Front-end > How to bind events in vue.js
How to bind events in vue.js: 1. Write the js method directly in the tag, the code is [f385b30ca3dc50ec4a2a59876cb41656 execution method The first way of writing 65281c5ac262bf6d81768915a4a77ac0]; 2. The method of calling method.
【Recommended related articles: vue.js】
vue.js binding Methods for defining events:
1. Write js methods directly in tags
<button v-on:click="alert('hi')">执行方法的第一种写法</button>
2. Methods for calling methods
<button v-on:click="run()">执行方法的第一种写法</button> <button @click="run()">执行方法的 简写 写法</button> export default { data () { return { msg: '你好vue', list:[] } }, methods:{ run:function(){ alert('这是一个方法'); } } }
(1) Method passing parameters, the method directly passes the parameters in the method when calling
<button @click="deleteData('111')">执行方法传值111</button> <button @click="deleteData('222')">执行方法传值2222</button>
(2) Passing in the event object
<button data-aid='123' @click="eventFn($event)">事件对象</button>
eventFn(e){ console.log(e); // e.srcElement dom节点 e.srcElement.style.background='red'; console.log(e.srcElement.dataset.aid); /*获取自定义属性的值*/ }
Related free learning Recommended: JavaScript(Video)
The above is the detailed content of How to bind events in vue.js. For more information, please follow other related articles on the PHP Chinese website!