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)建組件構(gòu)造器的方法寫彈窗組件,供大家參考,具體內(nèi)容如下
alert.js文件代碼
import Vue from 'vue' // 創(chuàng)建組件構(gòu)造器 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); // 回調(diào)函數(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; //關(guān)閉整個窗口 }, honorClose(){ //點擊關(guān)閉圖標 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>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
相關(guān)文章
vue實現(xiàn)用戶長時間不操作自動退出登錄功能的實現(xiàn)代碼
這篇文章主要介紹了vue實現(xiàn)用戶長時間不操作自動退出登錄功能的實現(xiàn)代碼,本文通過實例代碼給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-07-07基于el-table封裝的可拖拽行列、選擇列組件的實現(xiàn)
本文主要介紹了基于el-table封裝的可拖拽行列、選擇列組件的實現(xiàn),文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-12-12vue.js學(xué)習(xí)之UI組件開發(fā)教程
前端開發(fā)中,隨著業(yè)務(wù)的增多,出于效率的考慮,我們對于組件化開發(fā)的需求也越來越迫切。下面這篇文章主要給大家介紹了關(guān)于vue.js之UI組件開發(fā)的相關(guān)資料,文中介紹的非常詳細,需要的朋友們下面來一起看看吧。2017-07-07