vue分割面板封裝實(shí)現(xiàn)記錄
本文實(shí)例為大家分享了vue分割面板封裝實(shí)現(xiàn)的具體代碼,供大家參考,具體內(nèi)容如下
記錄一次 分割面板的封裝:
?<template> ? <div class="split-pane-wrapper" ref="outer"> ? ? <div class="pane pane-left" :style="{ width: leftOffsetPercent }"> ? ? ? <slot name="left"></slot> ? ? </div> ? ? <div ? ? ? class="pane-trigger-con" ? ? ? @mousedown="handleMousedown" ? ? ? :style="{ left: triggerLeft, width: `${triggerWidth}px` }" ? ? > ? ? //中間分割按鈕 ? ? ? <div class="pane-trigger-con__button"> ? ? ? ? <div v-for="i in 10" :key="i"></div> ? ? ? </div> ? ? </div> ? ? <div class="pane pane-right" :style="{ left: leftOffsetPercent }"> ? ? ? <slot name="right"></slot> ? ? </div> ? </div> </template> <script> export default { ? name: "SplitPane", ? props: { ? ? ? //分割值 ? ? value: { ? ? ? type: Number, ? ? ? default: 0.5, ? ? }, ? ? //按鈕寬度 ? ? triggerWidth: { ? ? ? type: Number, ? ? ? default: 8, ? ? }, ? ? //最大分割值/最小分割值 ? ? min: { ? ? ? type: Number, ? ? ? default: 0.1, ? ? }, ? ? max: { ? ? ? type: Number, ? ? ? default: 0.9, ? ? }, ? }, ? data() { ? ? return { ? ? ? // leftOffset: 0.3, ? ? ? canMove: false, ? ? ? initOffset: 0, ? ? }; ? }, ? computed: { ? ? ? //計(jì)算左邊面板的寬度 ? ? leftOffsetPercent() { ? ? ? return `${this.value * 100}%`; ? ? }, ? ? //右邊面板的marginleft ? ? triggerLeft() { ? ? ? return `calc(${this.value * 100}% - ${this.triggerWidth / 2}px)`; ? ? }, ? }, ? methods: { ? ? ? //鼠標(biāo)點(diǎn)擊 ?鼠標(biāo)移動(dòng)事件 ?計(jì)算偏差 ? ? handleMousedown(event) { ? ? ? document.addEventListener("mousemove", this.handleMousemove); ? ? ? document.addEventListener("mouseup", this.handleMouseup); ? ? ? this.initOffset = ? ? ? ? event.pageX - event.srcElement.getBoundingClientRect().left; ? ? ? this.canMove = true; ? ? }, ? ? //鼠標(biāo)移動(dòng)事件 計(jì)算移動(dòng)距離 ? ? handleMousemove(event) { ? ? ? if (!this.canMove) return; ? ? ? const outerRect = this.$refs.outer.getBoundingClientRect(); ? ? ? let offsetPercent = ? ? ? ? (event.pageX - ? ? ? ? ? this.initOffset + ? ? ? ? ? this.triggerWidth / 2 - ? ? ? ? ? outerRect.left) / ? ? ? ? outerRect.width; ? ? ? if (offsetPercent < this.min) offsetPercent = this.min; ? ? ? if (offsetPercent > this.max) offsetPercent = this.max; ? ? ? // this.$emit('input', offsetPercent) ? ? ? this.$emit("update:value", offsetPercent); ? ? }, ? ? handleMouseup() { ? ? ? this.canMove = false; ? ? }, ? }, }; </script> <style lang="scss"> .split-pane-wrapper { ? height: 100%; ? width: 100%; ? position: relative; ? .pane { ? ? position: absolute; ? ? top: 0; ? ? height: 100%; ? ? &-left { ? ? ? background: transparent; ? ? ? padding: 10px; ? ? ? box-sizing: border-box; ? ? } ? ? &-right { ? ? ? box-sizing: border-box; ? ? ? right: 0; ? ? ? bottom: 0; ? ? ? background: transparent; ? ? ? padding: 10px; ? ? } ? ? &-trigger-con { ? ? ? height: 100%; ? ? ? background: rgb(240, 240, 240); ? ? ? position: absolute; ? ? ? top: 0; ? ? ? z-index: 10; ? ? ? user-select: none; ? ? ? cursor: col-resize; ? ? ? .pane-trigger-con__button { ? ? ? ? border: 1px solid lightgrey; ? ? ? ? width: calc(100% - 2px); ? ? ? ? height: 20px; ? ? ? ? margin: 0 auto; ? ? ? ? position: relative; ? ? ? ? top: 50%; /*偏移*/ ? ? ? ? transform: translateY(-50%); ? ? ? ? border-radius: 2px; ? ? ? ? div { ? ? ? ? ? margin: 1px 0; ? ? ? ? ? width: 100%; ? ? ? ? ? height: 1px; ? ? ? ? ? background-color: lightgrey; ? ? ? ? } ? ? ? } ? ? } ? } } </style>
頁(yè)面使用split-pane:
?<div class="split-pane-con"> ? ? ? ? <split-pane :value.sync="offset"> ? ? ? ? ? <div slot="left"><el-input></el-input></div> ? ? ? ? ? <div slot="right"><el-input></el-input></div> ? ? ? ? </split-pane> ? </div> ? ? ?? ? data() { ? ? return { ? ? ? offset: 0.4, ? ? }; ? },
效果:
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
在vue使用echarts報(bào)錯(cuò):invalid dom問題
這篇文章主要介紹了在vue使用echarts報(bào)錯(cuò):invalid dom問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-03-03使用vue完成微信公眾號(hào)網(wǎng)頁(yè)小記(推薦)
公司最近有一個(gè)H5頁(yè)面的功能,比較簡(jiǎn)單的一個(gè)調(diào)查表功能,嵌套在我們微信公眾號(hào)里面。這篇文章主要介紹了使用vue完成微信公眾號(hào)網(wǎng)頁(yè)小記,需要的朋友可以參考下2019-04-04Vue.js實(shí)現(xiàn)網(wǎng)格列表布局轉(zhuǎn)換方法
下面小編就為大家?guī)硪黄猇ue.js實(shí)現(xiàn)網(wǎng)格列表布局轉(zhuǎn)換方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-08-08vue2中基于vue-simple-upload實(shí)現(xiàn)文件分片上傳組件功能
這篇文章主要介紹了vue2中基于vue-simple-upload的文件分片上傳組件,本文通過示例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-06-06使用vue-cli搭建SPA項(xiàng)目的詳細(xì)過程
vue-cli是vue.js的腳手架,用于自動(dòng)生成vue.js+webpack的項(xiàng)目模板,本文通過實(shí)例代碼給大家介紹vue-cli搭建SPA項(xiàng)目的詳細(xì)過程,感興趣的朋友跟隨小編一起看看吧2022-09-09Springboot+Vue-Cropper實(shí)現(xiàn)頭像剪切上傳效果
這篇文章主要為大家詳細(xì)介紹了Springboot+Vue-Cropper實(shí)現(xiàn)頭像剪切上傳效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-08-08