zoukankan      html  css  js  c++  java
  • vue封装弹窗

    封装代码

    <template>
      <div @touchmove="onTouchMove">
      <!-- 遮罩层动画 -->
        <div class="mask" @click="hideOnBlur && (WechatCustomer = false)" v-show="WechatCustomer"></div>
        <input style="display:none" v-model="WechatCustomer">
        <!-- 显示信息层 -->
        <transition :name="dialogTransition">
          <div class="popupBox" v-show="WechatCustomer">
            <slot></slot>
          </div>
        </transition>
      </div>
    </template>
    <script>
    export default {
      props: {
        //是否显示
        value: {
          type: Boolean,
          default: false
        },
        //弹窗动画
        dialogTransition: {
          type: String,
          default: "slide-fade"
        },
        //点击遮罩层关闭弹窗
        hideOnBlur: {
          default: function() {
            return true;
          }
        },
        //禁止页面滚动
        scroll: {
          type: Boolean,
          default: true
        }
      },
      created() {
        if (typeof this.value !== "undefined") {
          this.WechatCustomer = this.value;
        }
      },
      watch: {
        value(val) {
          this.WechatCustomer = val;
        },
        WechatCustomer(val) {
          this.$emit(val ? "on-show" : "on-hide");
          this.$emit("input", val);
        }
      },
      data() {
        return {
          // 传进来的值
          WechatCustomer: false
        };
      },
      methods: {
        onTouchMove: function(event) {
          !this.scroll && event.preventDefault();
        }
      }
    };
    </script>
    <style scoped>
    /*遮罩层*/
    .mask {
      position: fixed;
      z-index: 50;
      top: 0;
      right: 0;
      left: 0;
      bottom: 0;
      background: rgba(0, 0, 0, 0.5);
    }
    .popupBox {
      position: fixed;
      bottom: 1.875rem;
      left: 0px;
      max- 100%;
      max-height: 100%;
      min- 100%;
      min-height: 3.125rem;
      border-top-right-radius: 0.625rem;
      border-top-left-radius: 0.625rem;
      background: #fff;
      z-index: 99999999999;
      transform: translateY(0%);
      font-size: 0.3rem;
    }
    .slide-fade-enter-active {
      transition: all 0.3s ease;
    }
    .slide-fade-leave-active {
      transition: all 0.3s ease;
    }
    .slide-fade-enter,
    .slide-fade-leave-active {
      transform: translateY(100%);
      opacity: 0;
    }
    </style>
    

    页面调用封装弹窗:

    <Popup v-model="WechatCustomer">
     <!-- 弹窗内容 -->
      
    </Popup>
    
    //弹窗引入
    <script>
    import Popup from '../../components/popup/popup.vue'
    export default {
      data() {
          return {
            WechatCustomer:false
          }
      },
      components: {
          Popup
      },
    }
    </script>
    
  • 相关阅读:
    Vue的router和route的区别
    对cookie进行编解码用到的函数escape,unescape
    动态控制按钮的禁用和启用
    追踪算法总结
    MATLAB imread读取imwrite保存图片前后矩阵数据不一样
    图像质量评价和视频质量评价(IQA/VQA)
    c++ 使用torchscript 加载训练好的pytorch模型
    Transformer(self attention pytorch)代码
    tensorflow 单机多GPU训练时间比单卡更慢/没有很大时间上提升
    python+selenium爬取关键字搜索google图片
  • 原文地址:https://www.cnblogs.com/Intellectualscholar/p/15766036.html
Copyright © 2011-2022 走看看