vue.extend實現(xiàn)alert模態(tài)框彈窗組件
更新時間:2018年04月28日 08:56:57 作者:fongdaBoy
這篇文章主要為大家詳細介紹了vue.extend實現(xiàn)alert模態(tài)框彈窗組件,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文通過Vue.extend創(chuàng)建組件構造器的方法寫彈窗組件,供大家參考,具體內容如下
alert.js文件代碼
import Vue from 'vue' // 創(chuàng)建組件構造器 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); // 回調函數(shù) 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(){ //點擊其他區(qū)域 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實現(xiàn)用戶長時間不操作自動退出登錄功能的實現(xiàn)代碼
這篇文章主要介紹了vue實現(xiàn)用戶長時間不操作自動退出登錄功能的實現(xiàn)代碼,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-07-07基于el-table封裝的可拖拽行列、選擇列組件的實現(xiàn)
本文主要介紹了基于el-table封裝的可拖拽行列、選擇列組件的實現(xiàn),文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-12-12