1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > vue中的事件绑定v-on指令

vue中的事件绑定v-on指令

时间:2021-10-26 22:23:35

相关推荐

vue中的事件绑定v-on指令

v-on指令

用于事件绑定,v-on:事件名=“函数名(形参)”,可以简写成@事件名=“函数名(形参)”

例子:

<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title></head><body><id id="app"><input type="text" v-model="message" placeholder="输入...."><p>输入的内容:{{message}}</p><br><input type="button" value="haha" v-on:click="hell"><input type="button" value="hehe" @click="hell"></div></body><script src="/npm/vue/dist/vue.js"></script><script>var vue = new Vue({el: "#app",data: {message: "java"},methods:{hell:function(event){// event表示调用方法的对象,event.target.value表示获取调用这个方法对象的value值。alert(event.target.value);}}})</script></html>

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。