Vue系列七:事件处理
2019-05-18 13:28
190 查看
- 绑定监听:
v-on:xxx=“fun”
@xxx=“fun”
@xxx=“fun(参数)”
默认事件形参: event
隐含属性对象: $event - 事件修饰符:
.prevent : 阻止事件的默认行为 event.preventDefault()
.stop : 停止事件冒泡 event.stopPropagation() - 按键修饰符
.keycode : 操作的是某个keycode值的健
.enter : 操作的是enter键
<body> <div id="example"> <h2>1. 绑定监听</h2> <button @click="test1">test1</button> <button @click="test2('abc')">test2</button> <button @click="test3('abcd', $event)">test3</button> <h2>2. 事件修饰符</h2> <a href="http://www.baidu.com" @click.prevent="test4">百度一下</a> <div style="width: 200px;height: 200px;background: red" @click="test5"> <div style="width: 100px;height: 100px;background: blue" @click.stop="test6"></div> </div> <h2>3. 按键修饰符</h2> <input type="text" @keyup.13="test7"> <input type="text" @keyup.enter="test7"> </div> <script type="text/javascript" src="../js/vue.js"></script> <script type="text/javascript"> new Vue({ el: '#example', data: { }, methods: { test1(event) { alert(event.target.innerHTML) }, test2 (msg) { alert(msg) }, test3 (msg, event) { alert(msg+'---'+event.target.textContent) }, test4 () { alert('点击了链接') }, test5 () { alert('out') }, test6 () { alert('inner') }, test7 (event) { console.log(event.keyCode) alert(event.target.value) } } }) </script> </body>
相关文章推荐
- 04-Vue入门系列之Vue事件处理
- Vue入门系列(四)之Vue事件处理
- 04-Vue入门系列之Vue事件处理
- 一步一步学Silverlight 2系列(4):鼠标事件处理
- Microsoft .Net Remoting系列专题之三:Remoting事件处理全接触
- 深入理解DOM事件机制系列第二篇——事件处理程序
- 基于vue中对鼠标划过事件的处理方式详解
- 自定义View系列教程06--详解View的Touch事件处理
- Vue基础(事件处理)
- [ZZ]Microsoft .Net Remoting系列专题之三:Remoting事件处理全接触
- Vue.js 系列教程 1:渲染,指令,事件
- vue 事件绑定 处理-
- Microsoft .Net Remoting系列专题之三:Remoting事件处理全接触
- Microsoft .Net Remoting系列专题之三:Remoting事件处理全接触
- 自定义View系列教程06--详解View的Touch事件处理
- iOS事件处理系列1-事件的种类与处理流程
- 【脚本语言系列】关于 JavaScript 事件处理,你需要知道的事
- Microsoft .Net Remoting系列专题之三:Remoting事件处理全接触
- Microsoft .Net Remoting系列专题之三:Remoting事件处理全接触
- [C# 线程处理系列]专题五:线程同步——事件构造