vue.extend實(shí)現(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;
// 把a(bǔ)lertHonor.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">升級(jí)通知</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}, //達(dá)人昵稱
ranking:{type:String}, //排名
share:{type:Function}, //分享
},
data(){
return{
showAlertHonor:true
}
},
methods:{
alertHonorClick(){ //點(diǎn)擊其他區(qū)域
this.showAlertHonor = false; //關(guān)閉整個(gè)窗口
},
honorClose(){ //點(diǎn)擊關(guān)閉圖標(biāo)
this.showAlertHonor = false;
},
handleActions(action){
this.callback(action);
}
}
}
</script>
引用頁面代碼
<script>
import AlertHonor from '../alert.js'
export default{
data(){
return{
title:'我的榮譽(yù)'
}
},
ready(){
},
methods:{
back(){
alert(1)
},
submit(){
var vm = this;
AlertHonor({
title:'拜訪達(dá)人',
ranking:'您在全國(guó)排名第99',
share: function(){
vm.share();
}
});
},
share(){ //點(diǎn)擊分享
alert('分享');
},
}
}
</script>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Vue.js彈出模態(tài)框組件開發(fā)的示例代碼
- vue+element 模態(tài)框表格形式的可編輯表單實(shí)現(xiàn)
- 利用vue實(shí)現(xiàn)模態(tài)框組件
- vue+element模態(tài)框中新增模態(tài)框和刪除功能
- vue實(shí)現(xiàn)模態(tài)框的通用寫法推薦
- 詳解如何用VUE寫一個(gè)多用模態(tài)框組件模版
- vue移動(dòng)端模態(tài)框(可傳參)的實(shí)現(xiàn)
- 詳解vue父子組件關(guān)于模態(tài)框狀態(tài)的綁定方案
- Vue.extend 登錄注冊(cè)模態(tài)框的實(shí)現(xiàn)
- Vue?dialog模態(tài)框的封裝方法
相關(guān)文章
Vue監(jiān)聽localstorage變化的方法詳解
在日常開發(fā)中,我們經(jīng)常使用localStorage來存儲(chǔ)一些變量,這些變量會(huì)存儲(chǔ)在瀏覽中,對(duì)于localStorage來說,即使關(guān)閉瀏覽器,這些變量依然存儲(chǔ)著,方便我們開發(fā)的時(shí)候在別的地方使用,本文就給大家介紹Vue如何監(jiān)聽localstorage的變化,需要的朋友可以參考下2023-10-10
vue3.0中setup中異步轉(zhuǎn)同步的實(shí)現(xiàn)
這篇文章主要介紹了vue3.0中setup中異步轉(zhuǎn)同步的實(shí)現(xiàn)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-06-06
Vuex 在Vue 組件中獲得Vuex 狀態(tài)state的方法
今天小編就為大家分享一篇Vuex 在Vue 組件中獲得Vuex 狀態(tài)state的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-08-08
vue實(shí)現(xiàn)日歷表格(element-ui)
這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)日歷表格(element-ui),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-09-09
vue在手機(jī)中通過本機(jī)IP地址訪問webApp的方法
這篇文章主要介紹了vue在手機(jī)中通過本機(jī)IP地址訪問webApp的方法,需要的朋友可以參考下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項(xiàng)目中安裝依賴npm?install一直報(bào)錯(cuò)的解決過程
這篇文章主要給大家介紹了關(guān)于Vue項(xiàng)目中安裝依賴npm?install一直報(bào)錯(cuò)的解決過程,要解決NPM安裝依賴報(bào)錯(cuò),首先要分析出錯(cuò)誤的原因,文中將解決的過程介紹的非常詳細(xì),需要的朋友可以參考下2023-05-05
在Vue項(xiàng)目中用fullcalendar制作日程表的示例代碼
這篇文章主要介紹了在Vue項(xiàng)目中用fullcalendar制作日程表,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-08-08

