创建文件useMouse.js从vue模块引入onMounted,ref在onMounted中定义方法
import {onMounted
, ref
} from 'vue'
export default function useMouse() {
let x
= ref(0)
let y
= ref(0)
onMounted(() => {
window
.addEventListener('mousemove', e
=> {
x
.value
= e
.pageX
y
.value
= e
.pageY
})
})
return {x
, y
};
}
转载请注明原文地址: https://lol.8miu.com/read-21624.html