欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue?extend+promise封裝全局彈窗組件

 更新時(shí)間:2022年04月11日 13:50:59   作者:深圳最菜的前端  
這篇文章主要為大家詳細(xì)介紹了vue?extend+promise封裝全局彈窗組件,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了vue extend+promise封裝全局彈窗組件的具體代碼,供大家參考,具體內(nèi)容如下

因?yàn)轫?xiàng)目沒(méi)有引入第三方UI庫(kù),所以所有的公共組件都需要自己封裝
現(xiàn)在需要一個(gè)全局的彈窗,要有promise異步處理

實(shí)現(xiàn)后的效果

// components/confirm文件
<template>
? <div class="popup-wrap" v-if="showPopup">
? ? <div class="popup-center">
? ? ? <div class="popup-content">
? ? ? ? <div class="popup-close" @click="close"></div>
? ? ? ? <div class="title">{{ title }}</div>
? ? ? ? <div class="describe">{{ content }}</div>
? ? ? ? <div class="btn">
? ? ? ? ? <div :class="['btn-right', active == 'cancal' ? 'active' : '']" @click="handleClick('cancal')">{{cancelBtnText}}</div>
? ? ? ? ? <div :class="['btn-right', active == 'yes' ? 'active' : '']" @click="handleClick('yes')">{{yesBtnText}}</div>
? ? ? ? </div>
? ? ? </div>
? ? </div>
? </div>
</template>

<script>
export default {
? data() {
? ? return {
? ? ? showPopup: false,
? ? ? title: "", //標(biāo)題
? ? ? content: "", //提示文字
? ? ? yesBtnText: "", //確定按鈕
? ? ? cancelBtnText: "", //取消按鈕
? ? ? promiseStatus: null,
? ? ? active: "",
? ? };
? },
? watch: {},
? props: {},
? mounted () {
? ? this.confirm()
? },
? methods: {
? ? confirm() {
? ? ? this.showPopup = true;
? ? ? return new Promise((resolve, reject) => {
? ? ? ? this.promiseStatus = { resolve, reject };
? ? ? });
? ? },
? ? handleClick(e) {
? ? ? this.active = e;
? ? ? if (e == "yes") {
? ? ? ? this.promiseStatus && this.promiseStatus.resolve();
? ? ? } else {
? ? ? ? this.promiseStatus && this.promiseStatus.reject();
? ? ? }
? ? ? this.showPopup = false
? ? },
? ? close() {
? ? ? this.showPopup = false
? ? ? ?this.promiseStatus && this.promiseStatus.reject();
? ? ? // this.$emit("close");
? ? },
? },
};
</script>
<style lang="less" scoped>
.popup-wrap {
? width: 100%;
? height: 100%;
? background-color: rgba(0, 0, 0, 0.6);
? position: fixed;
? top: 0rem;
? left: 0rem;
? right: 0rem;
? bottom: 0rem;
? z-index: 9999;
? display: flex;
? align-items: center;
? justify-content: center;
? .popup-center {
? ? width: 990px;
? ? height: 413px;
? ? background-size: 990px 413px;
? ? display: flex;
? ? align-items: center;
? ? justify-content: center;
? ? .popup-content {
? ? ? position: absolute;
? ? ? width: 970px;
? ? ? height: 393px;
? ? ? background: linear-gradient(
? ? ? ? 180deg,
? ? ? ? rgba(5, 20, 39, 0.9) 0%,
? ? ? ? rgba(3, 17, 33, 0.9) 54%,
? ? ? ? rgba(1, 33, 74, 0.9) 100%
? ? ? );
? ? ? .popup-close {
? ? ? ? cursor: pointer;
? ? ? ? position: relative;
? ? ? ? top: 45px;
? ? ? ? left: 900px;
? ? ? ? width: 26px;
? ? ? ? height: 26px;
? ? ? ? border: 1px solid #fff;
? ? ? ? background-size: 100% 100%;
? ? ? }
? ? ? .title {
? ? ? ? text-align: center;
? ? ? ? margin-top: 50px;
? ? ? ? font-size: 40px;
? ? ? ? font-family: PingFangSC-Semibold, PingFang SC;
? ? ? ? font-weight: 600;
? ? ? ? color: #258df9;
? ? ? ? line-height: 56px;
? ? ? ? background: linear-gradient(180deg, #afebff 0%, #ffffff 100%);
? ? ? ? -webkit-background-clip: text;
? ? ? ? -webkit-text-fill-color: transparent;
? ? ? }
? ? ? .describe {
? ? ? ? text-align: center;
? ? ? ? margin-top: 30px;
? ? ? ? font-size: 28px;
? ? ? ? font-family: PingFangSC-Regular, PingFang SC;
? ? ? ? font-weight: 400;
? ? ? ? color: #a4bace;
? ? ? ? line-height: 40px;
? ? ? }
? ? }
? }
? .btn {
? ? width: 540px;
? ? height: 76px;
? ? margin: 0 auto;
? ? margin-top: 45px;
? ? display: flex;
? ? align-items: center;
? ? justify-content: space-between;
? ? .btn-right {
? ? ? cursor: pointer;
? ? ? width: 200px;
? ? ? height: 76px;
? ? ? border: 2px solid #a4bace;
? ? ? font-size: 30px;
? ? ? font-family: PingFangSC-Regular, PingFang SC;
? ? ? font-weight: 400;
? ? ? color: #a4bace;
? ? ? line-height: 76px;
? ? ? text-align: center;
? ? ? &.active {
? ? ? ? border: 2px solid #258df9;
? ? ? ? background: rgba(37, 141, 249, 0.3);
? ? ? ? color: #afebff;
? ? ? }
? ? }
? }
}
</style>
// js文件,這個(gè)文件看你們自己吧,寫(xiě)在哪里都可以
// utils/confirm.js
import Confirm from '@/components/confirm.vue'
import Vue from "vue";
const ConfirmBox = Vue.extend(Confirm);
/* @使用方法 this.$confirm進(jìn)行調(diào)用
?* this.$confirm("此操作將永久刪除該文件, 是否繼續(xù)?", "確定執(zhí)行刪除操作嗎", {
? ? ? cancelBtnText: "取消",
? ? ? yesBtnText: "確認(rèn)執(zhí)行",
? ? })
? ? .then(() => {
? ? ? console.log("點(diǎn)擊了確認(rèn)按鈕");
? ? })
? ? .catch(() => {
? ? ? console.log("點(diǎn)擊了取消按鈕cancel");
? ? });
?*/
? Confirm.install = (content, title, options) => {
? ? if (typeof title === 'object') {
? ? ? options = title;
? ? ? title = '';
? ? } else if (title === undefined) {
? ? ? title = '';
? ? }
??
? ? options = Object.assign({
? ? ? title: title,
? ? ? content: content,
? ? }, options);
??
? ? let instance = new ConfirmBox({
? ? ? data: options
? ? }).$mount();
? ? document.body.appendChild(instance.$el);
? ? return instance.confirm();
? };
// mine.js 在根路徑進(jìn)行掛載
import "@/util/confirm" // 引入js
import Confirm from '@/components/confirm' ?//Confirm組件
Vue.config.productionTip = false //阻止啟動(dòng)生產(chǎn)消息,常用作指令 ?消息提示的環(huán)境配置,設(shè)置為開(kāi)發(fā)環(huán)境或者生產(chǎn)環(huán)境
Vue.prototype.$confirm = Confirm.install; //Confirm組
// 使用?
// home.vue
<template>
?? ?<div @click="handleClick">點(diǎn)擊</div>
</template>

<script>
export.default = {
?? ?data () {},
?? ?methdos: {
?? ??? ?handleClick () {
?? ??? ??? ?this.$confirm("此操作將永久刪除該文件, 是否繼續(xù)?", "確定執(zhí)行刪除操作嗎", {
?? ??? ? ? ? ? ?cancelBtnText: "取消",
?? ??? ? ? ? ? ?yesBtnText: "確認(rèn)執(zhí)行",
?? ??? ? ? ? ?})
?? ??? ? ? ? ?.then(() => {
?? ??? ? ? ? ? ?console.log("點(diǎn)擊了確認(rèn)按鈕");
?? ??? ? ? ? ?})
?? ??? ? ? ? ?.catch(() => {
?? ??? ? ? ? ? ?console.log("點(diǎn)擊了取消按鈕cancel");
?? ??? ? ? ? ?});
?? ??? ?}
?? ?}
}
</script>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • el-form組件清除校驗(yàn)提示正確方法(前端技能提升)

    el-form組件清除校驗(yàn)提示正確方法(前端技能提升)

    el-form組件提供了表單驗(yàn)證的功能,可以通過(guò)在el-form上綁定rules屬性,并在el-form-item上設(shè)置prop屬性來(lái)進(jìn)行校驗(yàn),這篇文章主要給大家介紹了關(guān)于el-form組件清除校驗(yàn)提示正確方法(前端技能提升)的相關(guān)資料,需要的朋友可以參考下
    2023-12-12
  • vite+vue3項(xiàng)目集成ESLint與prettier的過(guò)程詳解

    vite+vue3項(xiàng)目集成ESLint與prettier的過(guò)程詳解

    這篇文章主要介紹了vite+vue3項(xiàng)目中集成ESLint與prettier的相關(guān)知識(shí),本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-09-09
  • 基于vue.js中事件修飾符.self的用法(詳解)

    基于vue.js中事件修飾符.self的用法(詳解)

    下面小編就為大家分享一篇基于vue.js中事件修飾符.self的用法詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-02-02
  • vueCli?4.x升級(jí)5.x報(bào)錯(cuò):Progress?Plugin?Invalid?Options的解決方法

    vueCli?4.x升級(jí)5.x報(bào)錯(cuò):Progress?Plugin?Invalid?Options的解決方法

    本文主要介紹了vueCli?4.x升級(jí)5.x報(bào)錯(cuò):Progress?Plugin?Invalid?Options的解決方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2024-01-01
  • vue不操作dom實(shí)現(xiàn)圖片輪播的示例代碼

    vue不操作dom實(shí)現(xiàn)圖片輪播的示例代碼

    這篇文章主要介紹了vue不操作dom實(shí)現(xiàn)圖片輪播的示例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-12-12
  • Vue使用三種方法刷新頁(yè)面

    Vue使用三種方法刷新頁(yè)面

    這篇文章說(shuō)明了如何使用Vue去刷新當(dāng)前頁(yè)面的多種方法實(shí)例,有完成的代碼提供參考,希望對(duì)你有所幫助
    2021-06-06
  • solid.js響應(yīng)式createSignal 源碼解析

    solid.js響應(yīng)式createSignal 源碼解析

    這篇文章主要為大家介紹了solid.js響應(yīng)式createSignal 源碼解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-09-09
  • Vue 解決在element中使用$notify在提示信息中換行問(wèn)題

    Vue 解決在element中使用$notify在提示信息中換行問(wèn)題

    這篇文章主要介紹了Vue 解決在element中使用$notify在提示信息中換行問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-11-11
  • echarts3如何清空上一次加載的series數(shù)據(jù)

    echarts3如何清空上一次加載的series數(shù)據(jù)

    這篇文章主要介紹了echarts3如何清空上一次加載的series數(shù)據(jù),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-10-10
  • vue實(shí)現(xiàn)簡(jiǎn)易音樂(lè)播放器

    vue實(shí)現(xiàn)簡(jiǎn)易音樂(lè)播放器

    這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)簡(jiǎn)易音樂(lè)播放器,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-08-08

最新評(píng)論