最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

vue中關于confirm確認框的用法

 更新時間:2023年08月21日 10:47:15   作者:王佑輝  
這篇文章主要介紹了vue中關于confirm確認框的用法,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教

vue中confirm確認框用法

示例圖片

示例圖1

示例代碼

this.$confirm("是否確認該操作","提示",{
    iconClass: "el-icon-question",//自定義圖標樣式
    confirmButtonText: "確認",//確認按鈕文字更換
    cancelButtonText: "取消",//取消按鈕文字更換
    showClose: true,//是否顯示右上角關閉按鈕
    type: "warning",//提示類型  success/info/warning/error
}).then(()=>{
    //確認操作
}).then((data) => {
    //取消操作
}).catch((err) => {
  	//捕獲異常
  	console.log(err);
});

vue自定義$confirm彈窗確認組件

1.Vue.extend()

使用基礎 Vue 構造器,創(chuàng)建一個“子類”。參數(shù)是一個包含組件選項的對象

.vue單文件經(jīng)過webpack打包之后是一個組件示例對象,因此可以傳到Vue.extend中生成一個包含此組件的類

2.new VueComponent().$mount()

new VueComponent() 創(chuàng)建實例,調(diào)用$mount()可以手動編譯

如果.$mount(’#app’)有參數(shù),表示手動編譯并且掛載到該元素上。

3.$el屬性 類型:string | HTMLElement

手動編譯后的示例對象中存在一個$el對象(dom元素),可以作為模板被插入到頁面中。

4.Vue.prototype 添加 Vue 實例方法

源碼

  • vue文件
<template>
<div :class="{'pop-up':true,'show':show}">
? ? <div class="popup-mask" v-if="hasMark"></div>
? ? <transition name="bottom">
? ? ? ? <div class="popup-note bottom">
? ? ? ? ? ? <div class="pop-content">
? ? ? ? ? ? ? ? <div class="pop-tit">
? ? ? ? ? ? ? ? ? ? {{title}}
? ? ? ? ? ? ? ? </div>
? ? ? ? ? ? ? ? <p class="pop-note hasTitle">
? ? ? ? ? ? ? ? ? ? <span class="msg" v-html="msg"></span>
? ? ? ? ? ? ? ? </p>
? ? ? ? ? ? ? ? <div class="btn-wrapper" v-if="type == 'alert'" @click.stop="alertClick">
? ? ? ? ? ? ? ? ? ? <span class="btn btn-block yes-btn">{{alertBtnText}}</span>
? ? ? ? ? ? ? ? </div>
? ? ? ? ? ? ? ? <div class="btn-wrapper" v-if="type == 'confirm'">
? ? ? ? ? ? ? ? ? ? <span @touchstart.prevent="noClick" class="btn">{{noBtnText}}</span>
? ? ? ? ? ? ? ? ? ? <span @touchstart.prevent="yesClick" class="btn yes-btn">{{yesBtnText}}
?? ??? ? ? ?</span>
? ? ? ? ? ? ? ? </div>
? ? ? ? ? ? </div>
? ? ? ? </div>
? ? </transition>
</div>
</template>
<script>
export default {
? ? props: {
? ? ? ? title: {
? ? ? ? ? ? type: String,
? ? ? ? ? ? default: '提示'
? ? ? ? },
? ? ? ? msg: {
? ? ? ? ? ? type: String,
? ? ? ? ? ? default: ''
? ? ? ? },
? ? ? ? type: {
? ? ? ? ? ? type: String,
? ? ? ? ? ? default: 'alert'
? ? ? ? },
? ? ? ? alertBtnText: {
? ? ? ? ? ? type: String,
? ? ? ? ? ? default: '我知道了'
? ? ? ? },
? ? ? ? yesBtnText: {
? ? ? ? ? ? type: String,
? ? ? ? ? ? default: '確定'
? ? ? ? },
? ? ? ? noBtnText: {
? ? ? ? ? ? type: String,
? ? ? ? ? ? default: '取消'
? ? ? ? },
? ? ? ? hasMark: {
? ? ? ? ? ? type: Boolean,
? ? ? ? ? ? default: true
? ? ? ? }
? ? },
? ? data() {
? ? ? ? return {
? ? ? ? ? ? promiseStatus: null,
? ? ? ? ? ? show: false
? ? ? ? }
? ? },
? ? methods: {
? ? ? ? confirm() {
? ? ? ? ? ? let _this = this;
? ? ? ? ? ? this.show = true;
? ? ? ? ? ? return new Promise(function (resolve, reject) {
? ? ? ? ? ? ? ? _this.promiseStatus = {resolve, reject};
? ? ? ? ? ? });
? ? ? ? },
? ? ? ? noClick() {
? ? ? ? ? ? this.show = false;
? ? ? ? ? ? this.promiseStatus && this.promiseStatus.reject();
? ? ? ? },
? ? ? ? yesClick() {
? ? ? ? ? ? this.show = false;
? ? ? ? ? ? this.promiseStatus && this.promiseStatus.resolve();
? ? ? ? },
? ? ? ? alertClick() {
? ? ? ? ? ? this.show = false;
? ? ? ? ? ? this.promiseStatus && this.promiseStatus.resolve();
? ? ? ? }
? ? }
}
</script>
<style lang='less'>
@import "../../../static/less/components/tip/index.less";
</style>
  • confirm.js
import Vue from 'vue'
import message from './message.vue'
const VueComponent = Vue.extend(message);
const vm = new VueComponent().$mount();
let init = false;
let defaultOptions = {
yesBtnText: '確定',
noBtnText: '取消'
};
const confirm = function (options) {
Object.assign(vm,defaultOptions , options,{
? ? type:'confirm'
});
if (!init) {
? ? document.body.appendChild(vm.$el);
? ? init = true;
}
return vm.confirm();
};
export default confirm;
  • 全局注冊
import confirm from './views/components/message/confirm'
Vue.prototype.$confirm = confirm;
  • 使用
this.$confirm({
? ? title: '',
? ? msg: '模式未保存,確定離開?',
? ? yesBtnText: "離開"
}).then(() => {
? ? console.log('yes')
? ? })
? ?.catch(() => {
? ? console.log('cancel')
});

總結

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關文章

  • vue3.0如何使用computed來獲取vuex里數(shù)據(jù)

    vue3.0如何使用computed來獲取vuex里數(shù)據(jù)

    這篇文章主要介紹了vue3.0如何使用computed來獲取vuex里數(shù)據(jù)問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-04-04
  • vue+echarts實現(xiàn)數(shù)據(jù)實時更新

    vue+echarts實現(xiàn)數(shù)據(jù)實時更新

    這篇文章主要為大家詳細介紹了vue+echarts實現(xiàn)數(shù)據(jù)實時更新,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-04-04
  • Vue3實現(xiàn)word轉成pdf代碼的方法

    Vue3實現(xiàn)word轉成pdf代碼的方法

    在Vue 3中,前端無法直接將Word文檔轉換為PDF,因為Word文檔的解析和PDF的生成通常需要在后端進行這篇文章主要介紹了Vue3實現(xiàn)word轉成pdf代碼的方法,需要的朋友可以參考下,
    2023-07-07
  • Vue.directive()的用法和實例詳解

    Vue.directive()的用法和實例詳解

    這篇文章主要介紹了Vue.directive()的用法和實例 ,需要的朋友可以參考下
    2018-03-03
  • vue實現(xiàn)自定義組件掛載原型上

    vue實現(xiàn)自定義組件掛載原型上

    這篇文章主要介紹了vue實現(xiàn)自定義組件掛載原型上方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-08-08
  • vue實現(xiàn)右上角時間顯示實時刷新

    vue實現(xiàn)右上角時間顯示實時刷新

    這篇文章主要為大家詳細介紹了vue實現(xiàn)右上角時間顯示實時刷新,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-10-10
  • 詳解vue之頁面緩存問題(基于2.0)

    詳解vue之頁面緩存問題(基于2.0)

    本篇文章主要介紹了vue之頁面緩存問題(基于2.0),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-01-01
  • Vue實現(xiàn)hash模式網(wǎng)址方式(就是那種帶#的網(wǎng)址、井號url)

    Vue實現(xiàn)hash模式網(wǎng)址方式(就是那種帶#的網(wǎng)址、井號url)

    這篇文章主要介紹了Vue實現(xiàn)hash模式網(wǎng)址方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-07-07
  • vue如何關閉prettier警告warn

    vue如何關閉prettier警告warn

    這篇文章主要介紹了vue如何關閉prettier警告warn問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-03-03
  • 前端Vue項目部署到服務器的全過程以及踩坑記錄

    前端Vue項目部署到服務器的全過程以及踩坑記錄

    使用Vue做前后端分離項目時,通常前端是單獨部署,用戶訪問的也是前端項目地址,因此前端開發(fā)人員很有必要熟悉一下項目部署的流程,下面這篇文章主要給大家介紹了關于前端Vue項目部署到服務器的全過程以及踩坑記錄的相關資料,需要的朋友可以參考下
    2023-05-05

最新評論

嘉峪关市| 临城县| 兴宁市| 陵水| 平原县| 五家渠市| 汾阳市| 宜川县| 贞丰县| 乐安县| 贡嘎县| 迁安市| 哈密市| 依兰县| 满城县| 密云县| 平谷区| 杂多县| 合江县| 大田县| 桦甸市| 吴川市| 兰西县| 体育| 子洲县| 大关县| 栾川县| 芜湖县| 资溪县| 平安县| 微山县| 桦川县| 化州市| 贡山| 安义县| 新竹市| 剑河县| 内乡县| 行唐县| 连云港市| 德江县|