当前位置: 首页 > news >正文

vue拖拽改变宽度

 1.封装组件ResizeBox.vue

<template><div ref="resize" class="resize"><div ref="resizeHandle" class="handle-resize" /><slot /></div>
</template>
<script>
export default {name: 'ResizeBox',props: {resizeConf: {type: Object,default: () => ({width: 280, // 初始宽度widthRange: [100, 500] // 宽度范围})}},mounted() {this.dragControllerDiv(this.$refs.resize, this.$refs.resizeHandle)},methods: {dragControllerDiv: function(resizeBox, resizeHandle) {resizeBox.style.width = this.resizeConf.width + 'px'// 鼠标按下事件resizeHandle.onmousedown = e => {const resizeWidth = resizeBox.offsetWidthconst startX = e.clientX // 水平坐标// 鼠标拖动事件document.onmousemove = ev => {const moveX = ev.clientXconst moveLen = resizeWidth + (moveX - startX)if (this.resizeConf.widthRange[0] <= moveLen && this.resizeConf.widthRange[1] >= moveLen) {resizeBox.style.width = moveLen + 'px'}}// 鼠标松开事件document.onmouseup = function() {document.onmousemove = nulldocument.onmouseup = null}}}}
}
</script>
<style lang="scss" scoped>
.resize {background: #fbfbfb;position: relative;word-wrap: break-word;.handle-resize {cursor: col-resize;position: absolute;right: -2px;width: 6px;height: 50px;border-left: 2px solid #c5c5c5;border-right: 2px solid #c5c5c5;top: calc(50% - 25px);}
}
</style>

 2.组件中使用

<template><div class="container sa-flex"><ResizeBox :resize-conf="resizeConf">我是左边我是左边我是左边我是左边我是左边我是左边我是左边我是左边我是左边我是左边</ResizeBox><div class="right sa-flex-1">我是右边我是右边我是右边我是右边我是右边我是右边我是右边我是右边我是右边我是右边</div></div>
</template>
<script>
import ResizeBox from './ResizeBox.vue'
export default {components: {ResizeBox},data() {return {resizeConf: {width: 280, // 初始宽度widthRange: [100, 500] // 宽度范围}}}
}</script>
<style lang="scss">
.sa-flex {display: flex;flex-wrap: no-wrap
}
.sa-flex-1 {flex:1
}
.container {min-height: 600px;background: #eee;
}
</style>

http://www.lryc.cn/news/104055.html

相关文章:

  • 华为数通HCIA-ARP(地址解析协议)详细解析
  • 【Python机器学习】实验04(1) 多分类(基于逻辑回归)实践
  • 【ChatGLM_01】ChatGLM2-6B本地安装与部署(大语言模型)
  • 谷歌Tsunami(海啸)扫描器搭建扩展使用教程
  • 诚迈科技承办大同首届信息技术产业峰会,共话数字经济崭新未来
  • 【Python】Python使用TK实现动态爱心效果
  • Unity3d C#快速打开萤石云监控视频流(ezopen)支持WebGL平台,替代UMP播放视频流的方案(含源码)
  • 【Android】APP启动优化学习笔记
  • docker的使用
  • iOS使用Rust调研
  • 抖音引流推广的几个方法,抖音全自动引流脚本软件详细使用教学
  • k8s概念-DaemonSet
  • Mac 终端快捷键设置:如何给 Mac 中的 Terminal 设置 Ctrl+Alt+T 快捷键快速启动
  • VR 变电站事故追忆反演——正泰电力携手图扑
  • fpga开发——蜂鸣器
  • 【Liux下6818开发板(ARM)】触摸屏
  • 苍穹外卖day11——数据统计图形报表(Apache ECharts)
  • 在制作PC端Game Launcher游戏启动器时涉及到的技术选型
  • SQL力扣练习(九)
  • 软考高级架构师笔记-10数学计算题
  • 设计模式五:建造者模式(Builder Pattern)
  • C++多线程编程(包含c++20内容)
  • 【C语言】通讯录2.0 (动态增长版)
  • 详解AMQP协议以及JAVA体系中的AMQP
  • 跨境电商外贸常态下,深度分析Live Market的优势
  • vue2企业级项目(八)
  • 小研究 - 主动式微服务细粒度弹性缩放算法研究(二)
  • 【雕爷学编程】Arduino动手做(177)---ESP-32 掌控板
  • 使用Gunicorn+Nginx部署Flask项目
  • 【12】STM32·HAL库开发-STM32时钟系统 | F1/F4/F7时钟树 | 配置系统时钟