vue3-resizable 是一个基于 Vue 3 的组件,提供了可调整大小和拖动功能,允许用户通过简单的拖动操作来自定义元素的尺寸和位置。并结合 any-touch 库有效地处理触摸事件,非常适合 PC 以及移动触摸设备。🚀
🐳 Vue 3 Composition API
🔥 用 TypeScript 编写
使用 npm 安装:
npm install vue3-resizable
使用 pnpm 安装:
pnpm install vue3-resizable
或者使用 yarn:
yarn add vue3-resizable
首先,确保在你的 Vue 项目中引入组件:
import { createApp } from "vue"
import App from "./App.vue"
import LResize from "vue3-resizable"
import "vue3-resizable/dist/index.css"
const app = createApp(App)
app.use(LResize)
app.mount("#app")
import { LResize } from "vue3-resizable"
import "vue3-resizable/dist/index.css"
<template>
<LResize
:minWidth="100"
:minHeight="100"
:maxWidth="300"
:maxHeight="300"
:initialWidth="150"
:initialHeight="150"
:initialTop="50"
:initialLeft="50"
:cssUnit="'px'"
:showDimension="true"
:showPosition="true"
>
<!-- 你可以在这里插入任何自定义内容 -->
<div>可调整大小的内容容器</div>
</LResize>
</template>
Prop | 类型 | 默认值 | 描述 |
---|---|---|---|
minWidth |
number |
30 |
最小宽度限制 |
minHeight |
number |
30 |
最小高度限制 |
maxWidth |
number |
无 |
最大宽度限制 |
maxHeight |
number |
无 |
最大高度限制 |
initialWidth |
number |
200 |
初始化宽度 |
initialHeight |
number |
200 |
初始化高度 |
initialTop |
number |
100 |
初始化上偏移 |
initialLeft |
number |
100 |
初始化左偏移 |
cssUnit |
'px' | 'rem' | string |
'px' |
宽高单位 |
showDimension |
boolean |
false |
是否显示尺寸信息 |
showPosition |
boolean |
false |
是否显示位置信息 |
style |
CSSProperties |
{} |
容器样式 |
handleStyle |
CSSProperties |
{} |
拖拽点样式 |
插槽名 | 说明 |
---|---|
default | 插入自定义内容 |
事件名 | 说明 | 参数 |
---|---|---|
boxUpdated | 当盒子尺寸或位置更新时触发 | BoxState |
参数名 | 类型 | 说明 |
---|---|---|
width |
number |
盒子的宽度 |
height |
number |
盒子的高度 |
top |
number |
盒子的顶部位置 |
left |
number |
盒子的左侧位置 |
zIndex |
number |
盒子的 z-index 值 |
方法名 | 说明 | 参数 |
---|---|---|
updateBoxStyle | 更新盒子样式 | () => void |
startDrag | 开始拖拽 | () => void |
endDrag | 拖拽结束 | () => void |
startResize | 开始调整大小 | () => void |
endResize | 调整大小结束 | () => void |
要参与此组件的开发,你可以克隆源代码仓库,并安装所有依赖:
git clone https://github.com/LostElkByte/vue3-resizable.git
cd vue3-resizable
npm install
欢迎通过发起 Issues 或提交 Pull Requests 来贡献你的代码。请确保你的代码符合项目的代码风格和质量标准。
此项目遵循 MIT 许可证发布。更多信息请查看 LICENSE
文件。