vue实现点击获取鼠标坐标
【代码】vue实现点击获取鼠标坐标。
·
<template>
<div id="#app">x:{{ a.x }} y:{{ a.y }}</div>
</template>
<script>
import { onMounted, onBeforeUnmount, reactive } from 'vue'
export default {
setup () {
const a = reactive({
x: 0,
y: 0
})
// const x = ref(0)
// const y = ref(0)
const up = (e) => {
a.x = e.pageX
a.y = e.pageY
console.log(e.pageX, e.pageY)
}
onMounted(() => {
window.addEventListener('click', up)
});
onBeforeUnmount(() => {
window.removeEventListener('click', up)
})
return {
a
}
}
}
</script>
更多推荐
已为社区贡献1条内容
所有评论(0)