<template>
  <div id="#app">x:{{ a.x }} y:{{ a.y }}</div>
</template>

<script>
import { onMounted, onBeforeUnmount, reactive } from 'vue'
export default {
  setup () {
    const a = reactive({
      x: 0,
      y: 0
    })
    // const x = ref(0)
    // const y = ref(0)
    const up = (e) => {
      a.x = e.pageX
      a.y = e.pageY
      console.log(e.pageX, e.pageY)
    }
    onMounted(() => {
      window.addEventListener('click', up)
    });
    onBeforeUnmount(() => {
      window.removeEventListener('click', up)
    })
    return {
      a
    }
  }
}
</script>

Logo

前往低代码交流专区

更多推荐