Vue监听事件实现计数点击依次增加的方法
2019/6/27 7:40:52
本文主要是介绍Vue监听事件实现计数点击依次增加的方法,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
1.实现计数器功能,每点击一次按钮,count值增加一或增加二,鼠标在cordinates行移动时会更新当前坐标,通过自定义函数或者stop属性禁止事件传播。
效果如下:
代码如下:
<!DOCTYPE html><html><head> <meta charset="utf-8"> <title>计数器自增函数</title> <script src="vue.js"></script></head><body> <div id="app"> <button v-on:click="increase">点击加一</button> <!--自定义步长--> <button v-on:click="increase2(2,$event)">点击加二</button> <p>{{count}}</p> <!--实现鼠标在此行移动时显示位置坐标--> <p v-on:mousemove="updateCordinates"> cordinates:({{x}}/{{y}})- <!--下面两种方法实现的效果相同--> <span v-on:mousemove="dummy">STOP UPDATE</span> <!--这里的stop后不能加小括号--> <span v-on:mousemove.stop>stop update too!</span> </p> </div> <script> new Vue({ el:'#app', data:{ count:0, x:0, y:0 }, methods:{ increase:function(){ this.count++; }, increase2:function (step,event){ this.count+=step; }, updateCordinates:function(event){ this.x=event.clientX; this.y=event.clientY; }, dummy:function(event){ event.stopPropagation(); } } }) </script></body></html>
注意:关键字,标签,括号等不能使用中文,否则也会出错。
以上这篇Vue监听事件实现计数点击依次增加的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持找一找教程网。
这篇关于Vue监听事件实现计数点击依次增加的方法的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-30React Native常用组件-点击组件
- 2024-05-30uniapp+vue3+uv-ui手机端后台OA管理模板
- 2024-05-29Python网络爬虫的时候json=就是让你少写个json.dumps()
- 2024-05-27React Native常用组件-展示组件
- 2024-05-27React Native常用组件-列表组件
- 2024-05-09vue3开发前端表单缓存自定义指令,移动端h5必备插件
- 2024-05-09React Hooks在class组件中的使用方式
- 2024-03-30[OIDC in Action] 2. 基于OIDC(OpenID Connect)的SSO(纯JS客户端)
- 2024-03-29terraform jsonencode
- 2024-03-13vuex-persist