mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-25 10:56:35 +08:00
types: improve useTouch typing
This commit is contained in:
parent
1dd4083102
commit
9e9f0e3d4d
@ -2,15 +2,15 @@ import { ref } from 'vue';
|
|||||||
|
|
||||||
const MIN_DISTANCE = 10;
|
const MIN_DISTANCE = 10;
|
||||||
|
|
||||||
|
type Direction = '' | 'vertical' | 'horizontal';
|
||||||
|
|
||||||
function getDirection(x: number, y: number) {
|
function getDirection(x: number, y: number) {
|
||||||
if (x > y && x > MIN_DISTANCE) {
|
if (x > y && x > MIN_DISTANCE) {
|
||||||
return 'horizontal';
|
return 'horizontal';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (y > x && y > MIN_DISTANCE) {
|
if (y > x && y > MIN_DISTANCE) {
|
||||||
return 'vertical';
|
return 'vertical';
|
||||||
}
|
}
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ export function useTouch() {
|
|||||||
const deltaY = ref(0);
|
const deltaY = ref(0);
|
||||||
const offsetX = ref(0);
|
const offsetX = ref(0);
|
||||||
const offsetY = ref(0);
|
const offsetY = ref(0);
|
||||||
const direction = ref('');
|
const direction = ref<Direction>('');
|
||||||
|
|
||||||
const isVertical = () => direction.value === 'vertical';
|
const isVertical = () => direction.value === 'vertical';
|
||||||
const isHorizontal = () => direction.value === 'horizontal';
|
const isHorizontal = () => direction.value === 'horizontal';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user