element ui 侧边栏手动缩放

html代码

<div @mousemove="shrinkMove" @mouseup="shrinkUp" style="width:100%; height:100%">
    <el-container>
        <el-aside :width="fatherWidth" class="bd-top flex" style="position:relative;">
            <aside-component></aside-component>
            <div class="resize" @mousedown="shrinkDown" title="Shrink sidebar"></div>
        </el-aside>
        <el-main style="background-color: var(--color-background)">
            <component :is="mainComponent"></component>
        </el-main>
    </el-container>
</div>

js代码

data() {
    return {
        mainComponent: "mainStartCom",
        isShrink: false,//控制是否改变宽度
    }
},
methods: {
    shrinkMove(e) {
        if (this.isShrink) {
            let wid = e.screenX + 5//误差值
            if (wid <= 65) {// 设定65为最短宽度
                this.$store.commit('changeCollapse', true)
                this.$store.commit('changeFatherWidth', '65px')
            }else {
                this.$store.commit('changeCollapse', false)
                this.$store.commit('changeFatherWidth', wid + 'px')
            }
        }
    },
    shrinkDown(e) {
        this.isShrink = true
    },
    shrinkUp(e) {
        this.isShrink = false
    }
}

css代码:

.resize {
    cursor: col-resize;
    position: absolute;
    right: 0;
    height: 100%;
    width: 5px;
}

copy其他人的,在自己项目里面使用了,没有问题,记录一下,方便后期查阅

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值