movable-view
移动组件。
Props
参数 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
direction | 'all' | 'vertical' | 'horizontal' | 'none' | none | 否 | movable-view的移动方向 |
x | number | string | 否 | 定义 x 轴方向的偏移,如果 x 的值不在可移动范围内,会自动移动到可移动范围;改变 x 的值会触发动画;单位支持px | |
y | number | string | 否 | 定义 y 轴方向的偏移,如果 y 的值不在可移动范围内,会自动移动到可移动范围;改变 y 的值会触发动画;单位支持px | |
animation | boolean | true | 否 | 是否使用动画 |
Events
事件名 | 说明 | 回调参数 |
---|---|---|
change | 拖动过程中触发的事件 | { x: number, y: number } |
Example
vue
<template>
<movable-area class="w-48 h-48 bg-gray-300">
<movable-view
class="bg-blue-400 w-12 h-12"
v-model:x="position.x"
v-model:y="position.y"
>😅</movable-view
>
</movable-area>
<button type="primary" @click="onMove">点击移动到(30px, 30px)</button>
</template>
<script setup lang="ts">
import { reactive } from 'vue'
const position = reactive({ x: 5, y: 5 })
const onMove = () => {
position.x = 30
position.y = 30
}
</script>