如下所示:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <script type="text/javascript" src="js/vue.js" ></script> <style> #canvas{ width: 500px; height: 500px; text-align: center; line-height: 500px; border: 1px solid #E5E5E5; margin: 0 auto; margin-top: 100px; } </style> </head> <body> <div id="app"> <div id='canvas' @mousemove='updateXY'> {{x}} {{y}} </div> </div> <script> new Vue({ el:'#app', data:{ x:0, y:0 }, methods:{ updateXY:function(event){ this.x=event.offsetX; this.y=event.offsetY } } }) </script> </body> </html>
以上这篇vue2.0获取鼠标位置的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。
您可能感兴趣的文章:
- 基于vue中对鼠标划过事件的处理方式详解
转载请注明出处:http://www.shandongyidao.com/article/20230526/300201.html