当前位置: 移动技术网 > IT编程>脚本编程>vue.js > Vue监听事件实现计数点击依次增加的方法

Vue监听事件实现计数点击依次增加的方法

2019年06月02日  | 移动技术网IT编程  | 我要评论

云南婚庆网,rock house jail,乐乐动漫网

1.实现计数器功能,每点击一次按钮,count值增加一或增加二,鼠标在cordinates行移动时会更新当前坐标,通过自定义函数或者stop属性禁止事件传播。

效果如下:

vue计数点击依次增加

代码如下:

<!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监听事件实现计数点击依次增加的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持移动技术网。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网