详解vue.js的事件处理器v

本篇文章主要介绍了详解vue.js的事件处理器v-on:click,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

用 v-on 指令监听 DOM 事件

注意:HTML5中不能使用v-on,换为@

(1)html代码:

<div> <button v-on:click="greet">Greet</button> // 或者 <button @click="greet">Greet</button> </div>

(2)js代码:

var vm = new Vue({ el: '#example', data: { name: 'Vue.js' }, // 在 `methods` 对象中定义方法 methods: { greet: function (event) { // 方法内 `this` 指向 vm alert('Hello ' + this.name + '!') // `event` 是原生 DOM 事件 alert(event.target.tagName) } } })

 (3)效果展示:

详解vue.js的事件处理器v

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wyffxf.html