跳到正文

Resizable 拖拽调整尺寸 ​

包裹容器并暴露拖拽手柄的原子组件:鼠标移到容器右缘 / 下缘时光标变为拉扯提示,按住拖动即可调整宽度 / 高度,支持 min / max 限制与 v-model 受控。

使用方式 ​

组件以 EmResizable 为名导出,全局注册后可直接使用:

vue
<script setup lang="ts">
import { ref } from 'vue'

const width = ref(320)
</script>

<template>
  <em-resizable v-model="width" axis="horizontal" :min="240" :max="480">
    <!-- 任意内容 -->
  </em-resizable>
</template>

手柄默认不显示视觉分隔线,仅鼠标悬停时出现 col-resize / row-resize 光标提示;如需显示分隔线,可设置 show-line。拖拽到达 min / max 边界时,光标自动回落为默认箭头,提示已无法继续拖拽。

水平拖拽 ​

垂直拖拽 ​

API ​

Resizable API ​

Props ​

属性类型默认值说明
axis'horizontal' | 'vertical''horizontal'调整方向:horizontal 沿水平轴(右缘拖宽)/ vertical 沿垂直轴(下缘拖高),默认 'horizontal' / Resize axis: horizontal (drag right edge) or vertical (drag bottom edge), default 'horizontal'
modelValuenumber—当前尺寸(v-model),单位 px;未传时使用 initial / Current size (v-model) in px; falls back to initial when omitted
initialnumber200初始尺寸(px),默认 200 / Initial size in px, default 200
fluidbooleanfalsefluid 弹性模式:未拖拽过且无受控值时不写内联尺寸,宽度交由 CSS(如侧栏基准 token)决定;首次拖拽以当前实际尺寸为起点,拖拽后内联 px 接管 / Fluid mode: no inline size until first drag (or controlled value), letting CSS (e.g. sidebar width token) decide; first drag starts from the current rendered size, inline px takes over afterwards
minnumber160最小尺寸(px),默认 160 / Minimum size in px, default 160
maxnumber—最大尺寸(px),默认不限制 / Maximum size in px, no limit by default
disabledbooleanfalse是否禁用拖拽,默认 false / Whether resizing is disabled, default false
handleSizenumber6手柄命中区尺寸(px),默认 6 / Handle hit area size in px, default 6
showLinebooleanfalse是否显示手柄视觉分隔线,默认 false(仅保留光标提示)/ Whether to show the visual divider line on the handle, default false (cursor hint only)

Events ​

事件名参数说明
update:model-valuesize: number拖拽过程中持续触发(v-model 同步,rAF 节流),负载为当前尺寸(px)/ Emitted continuously while dragging (v-model sync, rAF-throttled), payload is current size in px
resize-start—拖拽开始时触发一次(无负载)/ Emitted once when dragging starts (no payload)
resize-endsize: number拖拽结束时触发(pointerup),负载为最终尺寸(px)/ Emitted when dragging ends (pointerup), payload is final size in px