zoukankan      html  css  js  c++  java
  • vue 简易弹框

    很简易的弹出框,不想写样式了,凑活看吧在这里插入图片描述

    modal.vue

    <!--
     * @Description: 
     * @Version: 1.0
     * @author: shihaixia
     * @Date: 2021-09-14 15:38:27
    -->
    <template>
      <transition name="mask-bg-fade">
        <div class="modal" v-if="visible">
          <div
            class="modal-content"
            :style="{
              backgroundImage: 'url(' + backgroundImage + ')',
            }"
          >
            <header class="modal-head">
              <slot name="header">{{ title }}</slot>
            </header>
            <main>
              <slot></slot>
            </main>
            <footer class="modal-foot">
              <slot name="footer">
                <button @click="btnSave">确定</button>
                <button @click="btnClick">关闭</button>
              </slot>
            </footer>
          </div>
        </div>
      </transition>
    </template>
    
    <script>
    export default {
      data () {
        return {
    
        }
      },
      props: {
        visible: {
          type: Boolean,
          default: false
        },
        title: {
          type: String,
          default: "操作"
        },
        backgroundImage: {
          type: String,
          default: ""
        },
      },
      methods: {
        btnClick () {
          this.$emit("close")
        },
        btnSave () {
          this.$emit("confirm")
        }
      }
    }
    
    </script>
    
    <style>
    .modal {
       100%;
      height: 100%;
      background: rgba(0, 0, 0, 0.5);
      position: fixed;
      top: 0;
      left: 0;
      z-index: 99;
      align-items: center;
      display: flex;
    }
    .modal-content {
      position: fixed;
      left: 50%;
      transform: translateX(-50%);
      display: block;
      min- 300px;
      min-height: 300px;
      background: #fff;
      box-shadow: 0px 0px 10px 0px rgba(192, 196, 204, 1);
      border-radius: 6px;
      background-repeat: no-repeat;
      background-size: cover;
      margin: 0 auto;
    }
    .modal-head {
      font-size: 24px;
      /* border-bottom: 1px solid black; */
      margin: 20px 0;
      color: white;
    }
    .modal-foot {
      position: absolute;
      bottom: 10px;
    }
    </style>

    组件内使用

    <!--
     * @Description: 
     * @Version: 1.0
     * @author: shihaixia
     * @Date: 2021-09-14 14:57:57
    -->
    <template>
      <div class="hello">
        <button @click="visible = true" class="btn">插槽</button>
        <Modal
          :title="title"
          :visible.sync="visible"
          @confirm="confirm"
          @close="handleclose"
          :backgroundImage="backgroundImage"
        >
          <div class="content">内容</div>
          <!-- <template>
            <div class="hignlight">欢迎来到XXX!</div>
            <div class="content">是否封包</div>
          </template> -->
          <!-- 可自定义 footer -->
          <!-- <template slot="footer">
            <button class="btn" @click="visible = false">我知道了</button>
          </template> -->
        </Modal>
      </div>
    </template>
    
    <script>
    import Modal from "./Notice/Modal.vue";
    export default {
      name: "HelloWorld",
      components: {
        Modal,
      },
      props: {
      },
      data () {
        return {
          visible: false,
          title: "标题",
          backgroundImage: "https://st-gdx.dancf.com/gaodingx/0/uxms/design/20200425-114623-8814.png?x-oss-process=image/resize,w_932/interlace,1,image/format,webp"
        };
      },
      created () {
    
      },
      methods: {
        confirm () {
    
        },
        handleclose () {
          this.visible = false
        },
      }
    };
    </script>
    <style scoped>
    </style>
    请用今天的努力,让明天没有遗憾。
  • 相关阅读:
    std 迭代器的几种用法
    Cocos2dx3.1+xcode +lua配置
    php获取文件创建时间、修改时间
    如何创建一个基于jquery的编辑器
    封装ajax,简单的模仿jquery提交
    如何实现SQL事务的提交,又不对外进行污染
    .net mvc结合微软提供的FormsAuthenticationTicket登陆
    Http GET、Post方式的请求总结
    post 报文请求接口方法
    zip格式压缩、解压缩(C#)
  • 原文地址:https://www.cnblogs.com/cupid10/p/15291750.html
Copyright © 2011-2022 走看看