ResizeBox 可调整区域
用于需要拖拽改变尺寸的面板、侧栏或编辑器区域。
基础用法
拖动右侧或底部边缘
vue
<template>
<x-resize-box
v-model:width="width"
v-model:height="height"
:max-width="520"
:max-height="260"
:directions="['right', 'bottom']"
class="demo-resize-box"
>
拖动右侧或底部边缘
</x-resize-box>
</template>
<script setup lang="ts">
import { ref } from 'vue';
const width = ref(260);
const height = ref(120);
</script>受控尺寸
280 x 140
vue
<template>
<x-space>
<x-button @click="width = 240">宽 240</x-button>
<x-button @click="width = 320">宽 320</x-button>
<x-button @click="height = 120">高 120</x-button>
<x-button @click="height = 180">高 180</x-button>
</x-space>
<x-resize-box
v-model:width="width"
v-model:height="height"
:max-width="520"
:max-height="260"
:directions="['right', 'bottom']"
>
{{ width }} x {{ height }}
</x-resize-box>
</template>尺寸限制
宽度 200-360,高度 100-220
vue
<template>
<x-resize-box
v-model:width="width"
v-model:height="height"
:min-width="200"
:max-width="360"
:min-height="100"
:max-height="220"
:directions="['right', 'bottom']"
>
宽度 200-360,高度 100-220
</x-resize-box>
</template>四方向拖拽
四个方向均可拖拽
vue
<template>
<x-resize-box
v-model:width="width"
v-model:height="height"
:max-width="520"
:max-height="260"
:directions="['left', 'right', 'top', 'bottom']"
>
四个方向均可拖拽
</x-resize-box>
</template>自定义触发杆
自定义触发内容
拖动
调整高度
vue
<template>
<x-resize-box
v-model:width="width"
v-model:height="height"
:max-width="520"
:max-height="260"
:directions="['right', 'bottom']"
>
自定义触发内容
<template #resize-trigger="{ direction }">
<div class="demo-resize-trigger">
{{ direction === 'right' ? '拖动' : '调整高度' }}
</div>
</template>
</x-resize-box>
</template>自定义触发图标
自定义图标
vue
<template>
<x-resize-box :width="260" :height="120" :max-width="520" :directions="['right']">
自定义图标
<template #resize-trigger-icon="{ direction }">
<span>{{ direction === 'right' ? '⋮' : '⋯' }}</span>
</template>
</x-resize-box>
</template>拖拽事件
查看事件日志
vue
<template>
<x-resize-box
v-model:width="width"
v-model:height="height"
:max-width="520"
:max-height="260"
:directions="['right', 'bottom']"
@moving-start="pushLog('开始拖拽')"
@moving="(size) => pushLog(`拖拽中:${size.width} x ${size.height}`)"
@moving-end="pushLog('结束拖拽')"
>
查看事件日志
</x-resize-box>
</template>配合 LayoutSidebar
vue
<template>
<x-layout>
<x-layout-sidebar :width="220" :resize-directions="['right']">
可调整侧栏
</x-layout-sidebar>
<x-layout-content>内容区域</x-layout-content>
</x-layout>
</template>按需导入
ts
import { ResizeBox } from 'x-next';Props
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
width | 宽度 | number | - |
height | 高度 | number | - |
minWidth | 最小宽度 | number | 0 |
maxWidth | 最大宽度 | number | - |
minHeight | 最小高度 | number | 0 |
maxHeight | 最大高度 | number | - |
component | 渲染的 HTML 标签 | string | 'div' |
directions | 可拖拽方向 | Array<'left' | 'right' | 'top' | 'bottom'> | ['right'] |
Events
| 事件名 | 说明 | 回调参数 |
|---|---|---|
update:width | 宽度变化时触发 | width: number |
update:height | 高度变化时触发 | height: number |
moving-start | 拖拽开始时触发 | event: MouseEvent |
moving | 拖拽或键盘调整中触发 | { width, height }, event |
moving-end | 拖拽结束时触发 | event: MouseEvent |
Slots
| 插槽名 | 说明 | 参数 |
|---|---|---|
default | 内容 | - |
resize-trigger | 自定义拖拽杆内容 | { direction } |
resize-trigger-icon | 自定义拖拽杆图标 | { direction } |