Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(useMouse): support custom event extractor (#2991)
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
- Loading branch information
Showing
4 changed files
with
102 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,27 @@ | ||
<script setup lang="ts"> | ||
import { reactive } from 'vue' | ||
import { stringify } from '@vueuse/docs-utils' | ||
import { useMouse } from '@vueuse/core' | ||
import { useMouse, useParentElement } from '@vueuse/core' | ||
import type { UseMouseEventExtractor } from '@vueuse/core' | ||
const mouse = reactive(useMouse()) | ||
const text = stringify(mouse) | ||
const parentEl = useParentElement() | ||
const mouseDefault = reactive(useMouse()) | ||
const textDefault = stringify(mouseDefault) | ||
const extractor: UseMouseEventExtractor = event => ( | ||
event instanceof Touch | ||
? null | ||
: [event.offsetX, event.offsetY] | ||
) | ||
const mouseWithExtractor = reactive(useMouse({ target: parentEl, type: extractor })) | ||
const textWithExtractor = stringify(mouseWithExtractor) | ||
</script> | ||
|
||
<template> | ||
<pre lang="yaml">{{ text }}</pre> | ||
<p>Basic Usage</p> | ||
<pre lang="yaml">{{ textDefault }}</pre> | ||
<p>Extractor Usage</p> | ||
<pre lang="yaml">{{ textWithExtractor }}</pre> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters