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>
    
  • 相关阅读:
    数据结构 字符串的长度
    滚动条
    git push 一直卡在 writing objects 然后 就提交失败 提示:unexpected-disconnect-while-reading-sideband-packet
    vue中的防抖和节流
    html5中output元素详解
    手写 apply call bind 三个方法
    js中的陷阱!!!
    display:inline-block元素之间空隙的产生原因和解决办法
    git push到Gitee的时候上传不成功,可能是本地文件夹与远程仓库不同步
    axios没有实现jsonp这个功能,基于axios自己扩展一个
  • 原文地址:https://www.cnblogs.com/Intellectualscholar/p/15766036.html
Copyright © 2011-2022 走看看