vue.extend中怎么实现一个alert模态框弹窗组件

发布时间:2021-07-09 15:04:25 作者:Leah
来源:亿速云 阅读:89

这篇文章将为大家详细讲解有关vue.extend中怎么实现一个alert模态框弹窗组件,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。

alert.js文件代码

import Vue from 'vue'
// 创建组件构造器
const alertHonor = Vue.extend(require('./alert.vue'));

var currentMsg = {callback:function(){
}}

export default function(options){

  var alertComponent = new alertHonor({el: document.createElement('div')});
  alertComponent.title = options.title;
  alertComponent.ranking = options.ranking;
  // 把alertHonor.vue加入body中
  alertComponent.$appendTo(document.body);

  // 回调函数
  alertComponent.callback = function(action) {
    if (action == 'share') {
      options.share();
    }
  };

}

alert.vue代码

<template>
  <div class="alertHonor" v-if="showAlertHonor">
    <div class="alertHonorBox" @click="alertHonorClick"></div>
    <div class="honorWindow">
      <div class="honorClose" @click="honorClose"></div>
      <div class="honorBg">
        <div class="honorShare">
          <div class="honorBgLeft">升级通知</div>
          <div class="honorBgRight" @click='handleActions("share")'>分享</div>
        </div>
        <div class="honorText">{{title}}</div>
      </div>
      <div class="honorRanking">
        {{ranking}}
      </div>
    </div>
  </div>
</template>
<script>
  export default{
    props:{
      img:{type:String},  //图片
      title:{type:String},  //达人昵称
      ranking:{type:String},   //排名
      share:{type:Function}, //分享
    },
    data(){
      return{
        showAlertHonor:true
      }
    },
    methods:{
      alertHonorClick(){ //点击其他区域
        this.showAlertHonor = false; //关闭整个窗口
      },
      honorClose(){ //点击关闭图标
        this.showAlertHonor = false;
      },

      handleActions(action){
        this.callback(action);
      }
    }
  }
</script>

 引用页面代码

<script>
  import AlertHonor from '../alert.js'
  export default{
    data(){
      return{
        title:'我的荣誉'
      }
    },
    ready(){
    },
    methods:{
      back(){
        alert(1)
      },
      submit(){
        var vm = this;
        AlertHonor({
          
          title:'拜访达人',
          ranking:'您在全国排名第99',
          share: function(){
            vm.share();
          }
        });
      },
      share(){ //点击分享
        alert('分享');
      },
    }
  }
</script>

关于vue.extend中怎么实现一个alert模态框弹窗组件就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

推荐阅读:
  1. 使用Vue怎么实现一个命令式弹窗组件
  2. 详解基于Vue2.0实现的移动端弹窗(Alert, Confirm, Toast)组件

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

vue.extend alert

上一篇:EasyUI如何实现树形功能菜单

下一篇:vuex中怎么操作state对象

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》