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)閉圖標(biāo)
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監(jiān)聽localstorage變化的方法詳解
在日常開發(fā)中,我們經(jīng)常使用localStorage來存儲一些變量,這些變量會存儲在瀏覽中,對于localStorage來說,即使關(guān)閉瀏覽器,這些變量依然存儲著,方便我們開發(fā)的時候在別的地方使用,本文就給大家介紹Vue如何監(jiān)聽localstorage的變化,需要的朋友可以參考下2023-10-10
vue3.0中setup中異步轉(zhuǎn)同步的實現(xiàn)
這篇文章主要介紹了vue3.0中setup中異步轉(zhuǎn)同步的實現(xiàn)方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-06-06
Vuex 在Vue 組件中獲得Vuex 狀態(tài)state的方法
今天小編就為大家分享一篇Vuex 在Vue 組件中獲得Vuex 狀態(tài)state的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-08-08
vue-router中hash模式與history模式的區(qū)別
為了構(gòu)建 SPA(單頁面應(yīng)用),需要引入前端路由系統(tǒng),這就是 Vue-Router 存在的意義,而這篇文章主要給大家介紹了關(guān)于vue-router中兩種模式區(qū)別的相關(guān)資料,分別是hash模式、history模式,需要的朋友可以參考下2021-06-06
Vue項目中安裝依賴npm?install一直報錯的解決過程
這篇文章主要給大家介紹了關(guān)于Vue項目中安裝依賴npm?install一直報錯的解決過程,要解決NPM安裝依賴報錯,首先要分析出錯誤的原因,文中將解決的過程介紹的非常詳細,需要的朋友可以參考下2023-05-05
在Vue項目中用fullcalendar制作日程表的示例代碼
這篇文章主要介紹了在Vue項目中用fullcalendar制作日程表,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-08-08

