Skip to content

t-movable-view

MovableView 可移动视图

组件介绍

t-movable-view 是可移动的视图容器,必须在 t-movable-area 组件内使用。支持拖动、惯性、边界控制和缩放等功能,通过在视图层内部处理拖动,避免逻辑层和视图层之间的通信损耗。

平台兼容

HarmonyH5AndroidiOS小程序UTS

基础用法

基础用法参考 demo/movable/movable.uvue,在 t-movable-area 内使用。

vue
<template>
  <t-movable-area class="w-100% h-400 bg-#f5f5f5">
    <!-- 全方向拖动 -->
    <t-movable-view 
      direction="all" 
      :inertia="true" 
      :outOfBounds="false"
      :x="x" 
      :y="y"
      @change="onChange">
      <view class="w-100 h-100 bg-primary"></view>
    </t-movable-view>
  </t-movable-area>
</template>

<script setup>
const x = ref(0)
const y = ref(0)

function onChange(e: any) {
  console.log('位置变化:', e.detail.x, e.detail.y)
}
</script>

Props

属性名说明类型默认值
direction移动方向,可选 allverticalhorizontalnonestring'all'
inertia是否带有惯性booleanfalse
outOfBounds是否可以超出边界booleanfalse
xX 坐标number0
yY 坐标number0
damping阻尼系数number20
friction摩擦系数number2
disabled是否禁用booleanfalse
scale是否支持缩放booleanfalse
scaleMin最小缩放比例number0.5
scaleMax最大缩放比例number10
scaleValue缩放比例number1
animation是否使用动画booleantrue
path点击组件后跳转的页面路径string''
hover是否启用点击效果booleanfalse
type组件主题类型string''
effect组件显示主题string''
size组件尺寸string''

direction 可选值

说明
all全方向移动
vertical仅垂直方向移动
horizontal仅水平方向移动
none不可移动

Events

事件名说明回调参数
change拖动过程中触发{ x, y, source }
scale缩放过程中触发{ x, y, scale }

change 事件 source 值

说明
touch拖动
touch-out-of-bounds超出移动范围
out-of-bounds超出移动范围后的回弹
friction惯性
''setData

Slots

插槽名说明
default默认插槽,放置可移动的内容