Skip to content

鼠标坐标 中等 #Composable Function

By webfansplz @webfansplz

接受挑战    接受挑战(通过单元测试)    English

在使用Vue.js时,我们应该关注可复用性,可组合函数是一个很好的方式,让我们开始吧 👇:

<script setup lang="ts">

// Implement ...
function useEventListener(target, event, callback) {

}

// Implement ...
function useMouse() {
  useEventListener(window, "mousemove", () => {})
}
const { x, y } = useMouse()
</script>

<template>Mouse position is at: {{ x }}, {{ y }}</template>


分享你的解答 查看解答