vue一个超简单的菜单栏伸缩示例

代码

<template>
  <div class="container">
    <!-- 左侧区域 -->
    <div class="left-side" :style="{ width: leftWidth + 'px' }">
      左侧内容
    </div>
    
    <!-- 右侧区域 -->
    <div class="right-side" :style="{ left: leftWidth + 'px' }">
      <div class="content">
        <button @click="toggleLeftWidth">切换左侧宽度</button>
        <p>右侧内容区域,占据剩余空间</p>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      leftWidth: 200, // 初始宽度200px
      isCollapsed: false
    }
  },
  methods: {
    toggleLeftWidth() {
      this.isCollapsed = !this.isCollapsed;
      this.leftWidth = this.isCollapsed ? 64 : 200;
    }
  }
}
</script>

<style lang="less" scoped>
.container {
  position: relative;
  width: 100%;
  height: 100vh;
  overflow: hidden;
  .left-side {
    position: fixed;
    left: 0;
    top: 0;
    height: 100%;
    background-color: blue;
    transition: width 0.3s ease;
    padding: 20px;
    box-sizing: border-box;
  }

  .right-side {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    background-color: red;
    transition: left 0.3s ease;
    padding: 20px;
    box-sizing: border-box;
    overflow: auto;
    border-left: 1px solid #ddd;
  }
}



button {
  padding: 8px 16px;
  background-color: #42b983;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  margin-bottom: 20px;
}

button:hover {
  background-color: #3aa876;
}
</style>

结果

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值