vue使用‘:style‘控制动态width样式!

示例代码如下

<!-- eslint-disable vue/multi-word-component-names -->
<template>
  <!-- 整个页面 -->
  <div class="index">
    <!-- 左导航 -->
    <div class="leftNav" :style="{ width: leftNavWidth ,visibility: show ,transition: transitionParam}">
    </div>

    <!-- 主界面 -->
    <div class="mainSection" :style="{ width: mainSectionWidth,transition: transitionParam}"></div>
    <!-- mainSection -->
  </div>
  <!-- index -->
</template>

<script>
export default {
  // eslint-disable-next-line vue/multi-word-component-names
  name: "mainSection",
  data() {
    return {
      //接收从Login页传来的登录用户名
      user_name: localStorage.getItem('user_name'),
      //设置导航和主界面默认宽高
      leftNavWidth: "16%",
      mainSectionWidth: "84%",
      show:"visible",
      //过度0.5秒
      transitionParam:"width 0.5s ease"
    };
  },
  methods:{
    //控制导航和主界面的宽和高
    controlWidth() {
      console.log("已进入控制宽度方法");
      this.leftNavWidth = (this.leftNavWidth === '16%' ? '0%' : '16%');
      //控制左导航的显示与隐藏  同时设置mainSectionWidth的宽和高
      if(this.leftNavWidth === '16%') {
        this.show = 'visible'
        this.mainSectionWidth = '84%'
      }
      else if(this.leftNavWidth === '0%') {
        this.show = 'hidden'
        this.mainSectionWidth = '100%'
      }
    }
  }
};
</script>

<style>
</style>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值