zoukankan      html  css  js  c++  java
  • VUE 动态设置子组件弹窗的层级,解决弹窗层级失效问题

     

    VUE 动态设置子组件弹窗的层级,解决弹窗层级失效问题

     
     

    子组件点击更多,出弹窗,在其中存入全局的变量

       
     more() {
          // 此处是为了动态修改点出来弹窗的z-index 设置全局的一个变量 监听它
          this.$store.commit("getActive", 'middle');
          this.$nextTick(
            this.$refs.moreList.show("")
          )
        },
    

      

     
     

    父组件 template里面用参数定义z-index

    <!-- 右边 -->
            <div
              class="left-con"
              :class="this.$store.state.showCon ? '' : 'left-hide'"
              :style="show3D ? 'z-index: 5' : `z-index:${this.zIndexLeft}`"
            >
              <!--小区概况-->
              <sketchNew />
              <!-- 人员数量 -->
              <people-data />
              <!-- 房屋数量 -->
              <house-data />
              <!-- 人员进出 -->
              <peopleIn />
            </div>
     
     

    同时给z-index设置默认值

      data() {
        return {
          showButton: true,
          show3D: false,
          zIndexLeft: 50, // 非3D状态下默认值 解决百度地图和3D地图的下弹窗对层级不同要求的问题
          zIndexMiddle: 45, ///非3D状态下默认值
          zIndexRight: 40, //非3D状态下默认值
        };
     

    在计算属性获取和返回存储的active

      
    computed: {
        isActive() {
          return this.$store.state.active;
          console.log(this.$store.state.active);
        },
      },

     

    监听isActive,根据不同的类型,改变三个模块的z-index

     
    watch: {
        isActive: {
          async handler(oldV, newV) {
            console.log(oldV, newV);
            console.log("变化了");
            if (oldV === "middle") {
              this.zIndexMiddle = 100;
              this.zIndexLeft = 50;
              this.zIndexRight = 40;
              console.log("设置中间的z-index");
            } else if (oldV === "right") {
              this.zIndexRight = 100;
              this.zIndexMiddle = 45;
              this.zIndexLeft = 50;
              console.log("设置右边的z-index");
            } else if (oldV === "left") {
              this.zIndexLeft = 100;
              this.zIndexMiddle = 45;
              this.zIndexRight = 40;
              console.log("设置左边的z-index");
            }
          },
          immediate: true,
        },
      },
     

    你好,我是Jane,如果万幸对您有用,请帮忙点下推荐,谢谢啦~另外,咱们闪存见哦~
  • 相关阅读:
    python操作MySQL数据库(转)
    python3.3.2中的关键字(转)
    HashMap的键值需要注意什么?
    为什么基本类型不能做为HashMap的键值?
    怎么确保一个集合不能被修改?
    Iterator和 ListIterator有什么区别?
    Iterator怎么使用?有什么特点?
    迭代器Iterator是什么?
    哪些集合类是线程安全的?
    Queue的element()和peek()方法有什么区别?
  • 原文地址:https://www.cnblogs.com/jane-panyiyun/p/14626410.html
Copyright © 2011-2022 走看看