欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

vue2.0获取鼠标位置的方法

程序员文章站 2022-04-10 18:36:56
如下所示:

如下所示:

<!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获取鼠标位置的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。