<!-- 小贴士: 🎉 恭喜你成功解决了挑战,很高兴看到你愿意分享你的答案! 由于用户数量的增加,Issue 池可能会很快被答案填满。为了保证 Issue 讨论的效率,在提交 Issue 前,请利用搜索查看是否有其他人分享过类似的档案。 你可以为其点赞,或者在 Issue 下追加你的想法和评论。如果您认为自己有不同的解法,欢迎新开 Issue 进行讨论并分享你的解题思路! 谢谢! --> ```vue // 你的答案 ``` <template> Mouse position is at: {{ x }}, {{ y }} </template> <script setup > import { ref } from 'vue' function useEventListener(target, event, callback) { target.addEventListener(event, callback) } function useMouse() {// 定义一个名为 useMouse 的 composable 函数 const x = ref(0) const y = ref() // 使用 useEventListener 函数监听 mousemove 事件 useEventListener(window, "mousemove", (event) => { // 将鼠标的水平位置和垂直位置分别设置为响应式引用 x 和 y 的值 x.value = event.clientX y.value = event.clientY }) return { x, y } }// 返回包含 x 和 y 的对象 const { x, y } = useMouse() </script> <!-- 或者 Vue SFC Playground 在线链接 (https://sfc.vuejs.org) -->