当前位置: 移动技术网 > IT编程>脚本编程>vue.js > vue.extend实现alert模态框弹窗组件

vue.extend实现alert模态框弹窗组件

2018年05月11日  | 移动技术网IT编程  | 我要评论

head first java,南漂网事,走进科学古墓

本文通过vue.extend创建组件构造器的方法写弹窗组件,供大家参考,具体内容如下

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>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网