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

Vue ElementUI this.$confirm async await封裝方式

 更新時間:2022年09月23日 15:47:22   作者:asdfsdgfsdgfa  
這篇文章主要介紹了Vue ElementUI this.$confirm async await封裝方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教

Vue ElementUI this.$confirm async await封裝

this.$confirm官網(wǎng):

https://element.eleme.cn/#/zh-CN/component/message-box

改造前

? ? async test() {
? ? ? console.log("111111");
? ? ? this.$confirm("此操作將永久刪除該文件, 是否繼續(xù)?", "提示", {
? ? ? ? confirmButtonText: "確定",
? ? ? ? cancelButtonText: "取消",
? ? ? ? type: "warning",
? ? ? })
? ? ? ? .then(() => {
? ? ? ? ? console.log("點擊確定");
?
? ? ? ? ? this.$message({
? ? ? ? ? ? type: "success",
? ? ? ? ? ? message: "刪除成功!",
? ? ? ? ? });
? ? ? ? })
? ? ? ? .catch(() => {
? ? ? ? ? console.log("點擊取消");
?
? ? ? ? ? this.$message({
? ? ? ? ? ? type: "info",
? ? ? ? ? ? message: "已取消刪除",
? ? ? ? ? });
? ? ? ? });
? ? ? console.log("2222222");
? ? },

async await改造后

async test() {
? ? ? console.log("111111");
? ? ? let confirmRes = await this.$confirm(
? ? ? ? "此操作將永久刪除該文件, 是否繼續(xù)?",
? ? ? ? "提示",
? ? ? ? {
? ? ? ? ? confirmButtonText: "確定",
? ? ? ? ? cancelButtonText: "取消",
? ? ? ? ? type: "warning",
? ? ? ? }
? ? ? ).catch(() => {});
?
? ? ? if (confirmRes !== "confirm") {
? ? ? ? console.log("點擊取消");
? ? ? ? return;
? ? ? }
? ? ? console.log("點擊確定");
? ? ? console.log("2222222");
? ? }

一定要加上.catch(() => {});否則報錯

Vue elementUI組件封裝思路

核心

父子傳值、slot插槽

插槽傳值

<slot title=“123” name=“aaa”></slot>

父組件接收插槽值

<div slot=“aaa” slot-scope=“props” :value=“props.title”></div>

示例步驟

1、在components文件夾下新建一個MyComponent1文件夾,新建MyCompont1.vue

(以btn為例)

<template>
? <el-button-group>
? ? <el-button?
? ? ? ? v-for="(btn,index) in this.buttons"?
? ? ? ? :key="index"?
? ? ? ? :type="btn.type ? btn.type:'primary'"
? ? ? ? :icon="btn.icon"?
? ? ? ? :size="btn.size?btn.size:'mini'"
? ? ? ? @click="btn.click"
? ? >
? ? ? ? {{btn.label}}
? ? </el-button>
? </el-button-group>
</template>
<script>
export default {
? name: 'MyComponent1', // name就是封裝好后使用的組件名
? props: {
? ? buttons: {
? ? ? type: Array,
? ? ? required: true
? ? }
? }
}
</script>

2、components文件夾下新建index.js, 用于注冊組件,也可以在main.js中注冊,為了統(tǒng)一管理建議放在components中注冊

3、然后main.js中引入,就可以直接使用了**

注冊

import Vue from 'vue'
import MyComponent1 from './MyComponent1/index.vue'
//多個組件就多次注冊
Vue.component(MyComponent1.name, MyComponent1)
''

使用

<template>
? <div>
? ? <MyComponent1 :buttons="buttons"></MyComponent1>
? </div>
</template>
<script>
export default {
? name: '',
? data () {
? ? return {
? ? ? buttons: [{
? ? ? ? label:'創(chuàng)建',
? ? ? ? icon:'el-icon-circle-plus-outline',
? ? ? ? click: ()=>{console.log('創(chuàng)建')}
? ? ? },{
? ? ? ? label:'修改',
? ? ? ? icon:'el-icon-edit-outline',
? ? ? ? click: ()=>{console.log('修改')}
? ? ? }]
? ? }
? }
}
</script>

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

相關(guān)文章

  • Vue2.0實現(xiàn)自適應(yīng)分辨率

    Vue2.0實現(xiàn)自適應(yīng)分辨率

    這篇文章主要為大家詳細(xì)介紹了Vue2.0實現(xiàn)自適應(yīng)分辨率,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-11-11
  • 在vue項目實現(xiàn)一個ctrl+f的搜索功能

    在vue項目實現(xiàn)一個ctrl+f的搜索功能

    剛剛接到領(lǐng)導(dǎo)通知,需要實現(xiàn)搜索功能,因為項目是vue的而且是手機端,對我來說有點小難度。經(jīng)過小編的一番思索最終還是解決了,今天小編把實現(xiàn)過程分享到腳本之家平臺,需要的朋友參考下
    2020-02-02
  • Vue-Router滾動行為的具體使用

    Vue-Router滾動行為的具體使用

    在 Vue Router 中,你可以使用滾動行為來定義路由切換時頁面滾動的行為,本文就詳細(xì)的介紹一下Vue-Router滾動行為的具體使用,感興趣的可以了解一下
    2023-08-08
  • 基于Vue設(shè)計實現(xiàn)一個彈幕組件

    基于Vue設(shè)計實現(xiàn)一個彈幕組件

    這篇文章主要給大家分享一個開發(fā)中常見的需求,接下來將為大家詳細(xì)介紹彈幕的實現(xiàn)以及設(shè)計思路一步一步描述出來,希望大家能夠喜歡
    2023-06-06
  • Vue Router的手寫實現(xiàn)方法實現(xiàn)

    Vue Router的手寫實現(xiàn)方法實現(xiàn)

    這篇文章主要介紹了Vue Router的手寫實現(xiàn)方法實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-03-03
  • 詳解為什么Vue中的v-if和v-for不建議一起用

    詳解為什么Vue中的v-if和v-for不建議一起用

    這篇文章主要介紹了面試官:為什么Vue中的v-if和v-for不建議一起用,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-01-01
  • vue調(diào)用微信JSDK 掃一掃,相冊等需要注意的事項

    vue調(diào)用微信JSDK 掃一掃,相冊等需要注意的事項

    這篇文章主要介紹了vue調(diào)用微信JSDK 掃一掃,相冊等需要注意的事項,幫助大家更好的理解和使用vue框架,感興趣的朋友可以了解下
    2021-01-01
  • vue彈窗組件使用方法

    vue彈窗組件使用方法

    彈窗是一個項目必備的復(fù)用利器,這篇文章主要介紹了vue彈窗組件的使用方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-04-04
  • 在vue中使用G2圖表的示例代碼

    在vue中使用G2圖表的示例代碼

    這篇文章主要介紹了在vue中使用G2圖表的示例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2019-03-03
  • 在vue-cli搭建的項目中增加后臺mock接口的方法

    在vue-cli搭建的項目中增加后臺mock接口的方法

    這篇文章主要介紹了在vue-cli搭建的項目中增加后臺mock接口的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-04-04

最新評論

金山区| 娄烦县| 长治市| 台安县| 台北市| 图们市| 连南| 黄浦区| 临安市| 桐乡市| 淮阳县| 获嘉县| 景泰县| 弋阳县| 霍州市| 秦安县| 保定市| 和田市| 惠安县| 盖州市| 炎陵县| 张家港市| 林西县| 阿荣旗| 吴川市| 西充县| 新闻| 荥经县| 宁夏| 阳泉市| 建阳市| 曲周县| 卫辉市| 曲阜市| 图木舒克市| 卓尼县| 灌云县| 湾仔区| 富平县| 东乡县| 兴宁市|