【vue3】四、onMounted、onCreated等使用

it2024-12-23  12

创建文件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};//x,y可以在组件中使用 }
最新回复(0)