1.自定义方法

import { reactive, onMounted, onUnmounted } from 'vue'
export function MouseMovement() {
  let mouse = reactive({ x: 0, y: 0 })
  function update(e) {
    mouse.x = e.pageX;
    mouse.y = e.pageY;
  }
  onMounted(() => {
    window.addEventListener("mousemove", update);
  })
  onUnmounted(() => {
    window.removeEventListener("mousemove", update);
  })
  return mouse
}

2.调用方法

<template>
  <img :src="'xxx.png'" alt=""
    :style="'left:' + (mousePosition.x + 10) + 'px;top:' + (mousePosition.y + 10) + 'px;position: fixed;'">
</template>
<script setup>
import { MouseMovement } from './json'
const mousePosition = MouseMovement(); // 获取鼠标位置
</script>

一沙一世界,一花一天堂。君掌盛无边,刹那成永恒。