vue组件系列1、弹窗

vue组件系列1、弹窗

建立vue文件 pre_message.vue,直接源码,注释很详细

 <template>
  <div class="my_dialog">
    <!--外层的遮罩 点击事件用来关闭弹窗,isShow控制弹窗显示 隐藏的props-->
    <div
      class="dialog-cover"
      v-if="pre_show"
      @click="closeMyself"
    ></div>
    <!-- transition 这里可以加一些简单的动画效果 -->
    <transition name="drop">
      <!--style 通过props 控制内容的样式  -->
      <div
        class="dialog-content"
        v-if="pre_show"
      >
        <div :class="pre_showtype">
          <!--弹窗头部 title-->
          <slot name="header">{
   {pre_title}}</slot>
        </div>
        <div class="dialog_main">
          <!--弹窗的内容-->
          <slot name="main">{
   {pre_note}}</slot>
        </div>
        <!--弹窗关闭按钮-->
        <div
          class="foot_close"
          @click="closeMyself"
        >
          <div class="close_img back"></div>
        </div>
      </div>
    </transition>
  </div>
</template> 

<script>
/*
名称:弹窗组件
日期:2019-03-14
作者:hj
步骤:
先搭建组件的html和css样式,遮罩层和内容层。
调用:


*/
export default {
  /*组件名称不能和系统关键字重复*/ 
  name: "pre_message",
  data() {
    return {
      pre_show:false,
      pre_showtype:'dialog_head dialog_head_none',
      pre_title:'提示',
      pre_note:'说明信息没有获取到',
    }
  },
  props: {        
    // 展示类型
    showtype:{
      type:String,
      default:''
    },
    // 展示内容
    note:{
      type:String,
      default:''
    },
    message_data: {
      type: Object,
      default: function () {
        return { showtype: 'dialog_head dialog_head_none',note:'对象模式' }
      }
    }
  },
  watch:{    
    note(val){
      this.my_note=val;
      console.log('展示'+this.note+' my_note='+this.my_note);
      this.refresh_data();
    },
    message_data(obj){
      this.check_obj();
    }
  },
  methods: {
    closeMyself() {
      console.log('关闭');
      // this.$emit("on-close");
      this.pre_show=false;
    },
    refresh_data:function(){
      console.log('子组件数据刷新...');
      this.pre_show=true;
      this.pre_title='提示';
      this.pre_note=this.note;
    },
    check_obj:function(){
      // console.log('传入');
      // console.log(this.message_data);
      switch(this.message_data.showtype){
        case 'ok':
          this.pre_showtype='dialog_head dialog_head_ok';
          this.pre_title='通过';
          break;
        case 'no':
          this.pre_showtype='dialog_head dialog_head_no';
          this.pre_title='拒绝';
          break;
        case 'err':
          this.pre_showtype='dialog_head dialog_head_err';
          this.pre_title='错误';
          break;
        case 'warning':
          this.pre_showtype='dialog_head dialog_head_warning';
          this.pre_title='警告';
          break;
        default:
          this.pre_showtype='dialog_head dialog_head_none';
          break;
      }
      this.pre_note=this.message_data.note;
      this.pre_show=true;
    }
  }
};
</script>


<style lang="scss" scoped>
/*
scss 依赖安装
npm  install -s sass-loader
npm install -s node-sass
*/
/** 弹窗动画*/
.drop-enter-active {
  // 动画进入过程:0.5s
  transition: all 0.5s ease;
}
.drop-leave-active {
  // 动画离开过程:0.5s
  transition: all 0.3s ease;
}
.drop-enter {
  //动画之前的位置
  transform: translateY(-500px);
}
.drop-leave-active {
  //动画之后的位置
  transform: translateY(-500px);
}
// 最外层 设置position定位
.my_dialog {
  position: relative;
  color: #2e2c2d;
  font-size: 16px;
}
// 遮罩 设置背景层,z-index值要足够大确保能覆盖,高度 宽度设置满 做到全屏遮罩
.dialog-cover {
  background: rgba(0, 0, 0, 0.8);
  position: fixed;
  z-index: 200;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}
// 内容层 z-index要比遮罩大,否则会被遮盖,
.dialog-content {
  position: fixed;
  width: 40%;
  top: 35%;
  left: 30%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 300;

  .dialog_head {
    // 头部title的背景 居中圆角等属性。
    // width: 86.5%;
    width: 100%;
    height: 43px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 24px;
    padding: 5px 50px 10px 50px;
    border-top-left-radius: 10px;
    border-top-right-radius: 10px;
  }
  .dialog_head_ok {
    background-color: #45f79f;
  }
  .dialog_head_no {
    background-color: #72837a;
  }
  .dialog_head_warning {
    background-color: #f4fb8e;
  }
  .dialog_head_err {
    background-color: #f31b2a;
  }
  .dialog_head_none {
    background-color: #ffffff;
  }
  .dialog_main {
    // 主体内容样式设置
    background: #ffffff;
    display: flex;
    justify-content: center;
    align-content: center;
    // width: 86.5%;
    width: 100%;
    padding: 22px 50px 47px 50px;
    border-bottom-left-radius: 10px;
    border-bottom-right-radius: 10px;
  }
  .foot_close {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #fcca03;
    display: flex;
    justify-content: center;
    align-content: center;
    position: absolute;
    right: -60px;
    top: -6px;
    .close_img {
      background-image: url("../../assets/image/shan1.png");
      width: 20px;
      height: 20px;
    }
  }
}
</style>

父组件使用

<template>
  <div class="mydiv">    
    <button @click="tt">测试</button>
    <button @click="tt_ok">通过</button>
    <button @click="tt_no">拒绝</button>
    <button @click="tt_err">错误</button>
    <button @click="tt_warning">警告</button>
    <!-- 放置自定义组件 -->    
    <per-message
      ref="child1"
      v-bind:note="setnote"
      :message_data="msg_obj"
      @on-close="closeDialog"
    />
  </div>
</template>

<script>
// import testmessage2 from "./personmode/pre_message.vue";
export default {  
  components: {
    // 'per-message':testmessage2,
    'per-message':()=>import("./personmode/pre_message.vue"),
  },
  data() {
    return {
      setnote:'',
      msg_obj:{}
    };
  },
  mounted: function() {
    this.$nextTick(function(ischeck) {
      
    });
    // 这里只是操作dom
    // console.log('验证结果='+res);
    // console.log(this.ischeck.isok);
    // this.$set(this.ischeck, 'isok', '1')
  },
  watch: {    
    // 这里写方法会影响性能
  },
  methods: {
    closeDialog(){
      this.show_msg=false;
    //把绑定的弹窗数组 设为false即可关闭弹窗
    },
    tt:function(){
      console.log('弹窗');
      // 方式1弹出
      // this.setnote='新内容'+(Math.random() * 35);
      // /*
      // 直接 
      // this.$refs.child1.refresh_data();
      // 会导致参数没有传过去,界面已经弹出
      // */ 
      // var that=this;
      // this.$nextTick(function(ischeck) {
      //   that.$refs.child1.refresh_data();
      // });
      // 方式2监听弹出
      this.setnote='监听弹出'+(Math.random() * 35);
    },
    tt_ok:function(){
      this.msg_obj={'showtype':'ok','note':'通过检查'};
    },
    tt_no:function(){
      this.msg_obj={'showtype':'no','note':'检查失败'};
    },
    tt_err:function(){
      this.msg_obj={'showtype':'err','note':'发现错误'};
    },
    tt_warning:function(){
      this.msg_obj={'showtype':'warning','note':'警告。。。。。。。。。'};
    }
    
  }
};

</script>
<style scoped>
</style>

 

转载于:https://my.oschina.net/qingqingdego/blog/3022522

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/101049.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Java酒店管理系统_java酒店管理系统报告

    Java酒店管理系统_java酒店管理系统报告基于jsp+servlet+pojo+mysql实现一个javaee/javaweb的小型酒店管理系统,该项目可用各类java课程设计大作业中,小型酒店管理系统的系统架构分为前后台两部分,最终实现在线上进行小型酒店管理系统各项功能,实现了诸如用户管理,登录注册,权限管理等功能,并实现对各类小型酒店管理系统相关的实体进行管理。该小型酒店管理系统为一个采用mvc设计模式进行开发B/S架构项…

    2022年9月24日
    0
  • Centos中查看有哪些用户

    Centos中查看有哪些用户

    2021年9月6日
    55
  • Raid5磁盘阵列修复方法介绍「建议收藏」

    Raid5磁盘阵列修复方法介绍「建议收藏」  在RAID5中,数据条带化后存储在分布式奇偶校验的多个磁盘上。分布式奇偶校验的条带化意味着它将奇偶校验信息和条带化数据分布在多个磁盘上,这样会有很好的数据冗余。而有时候raid5磁盘阵列损坏,我们该如何修复呢?  1.若单个硬盘失效,尝试热插拔,即拔下来再插上去;如果不能解决,则进入RAID配置界面,将该硬盘进行ForceOnLine操作;如果不能解决,尝试更换-其它硬盘…

    2022年4月28日
    1.4K
  • 【Oracle错误】unable to connect 08004 ora12154

    【Oracle错误】unable to connect 08004 ora12154从网上得知,oracle有个bug:连oracle的程序exe的路径中如果包含(、还有啥特殊字符的时候,就连不上,报错误ora12154。我今天也遇到了,我在EA连oracle的时候,死活要报这个错,后来把EA的安装目录从C:\ProgramFiles(x86)中剪贴到没有()的地方,就可以了。参考链接:http://www.2cto.com/database/201

    2022年7月24日
    13
  • poj 1845(等比数列前n项和及高速幂)

    poj 1845(等比数列前n项和及高速幂)

    2022年2月5日
    45
  • 妳不能不知道的部落格(zz)

    妳不能不知道的部落格(zz)妳不能不知道的部落格這是我給 微電腦傳真 的稿子 據說是刊登在五月號 第 207 期 上但是由於邀稿者離職之故 大概不會刊登出來了 以下為全文 共約一萬五千字 請注意這些內容使用需註明出處 未經允許不得作為商業使用 商業用書面印刷權目前僅授予微電腦傳真雜誌 妳不能不知道的部落格 Blog 是甚麼碗糕啊 源起 Blog 指的並非任何一套特定的軟體 也不是特定的系統或服務 Blog 實

    2025年7月6日
    0

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号