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

vue?elementUI之this.$confirm的使用方式

 更新時(shí)間:2023年08月21日 14:26:52   作者:*且聽(tīng)風(fēng)吟  
這篇文章主要介紹了vue?elementUI之this.$confirm的使用方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

vue elementUI之this.$confirm的使用

當(dāng)進(jìn)行一些操作時(shí),有時(shí)需要彈出一些確定信息,

一般有兩種形式:提示框和確認(rèn)框。

通常為一個(gè)確定動(dòng)操作,一個(gè)取消操作,如下:

this.$confirm(`您確定刪除嗎?`, '提示', {
          confirmButtonText: '確定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          // 確定操作
        }).catch(() => {
          // 取消操作
          this.$message({
            type: 'info',
            message: '已取消'
          })
})

頁(yè)面效果:

默認(rèn)情況下,當(dāng)用戶點(diǎn)擊取消按鈕觸發(fā)取消和點(diǎn)擊關(guān)閉按鈕或遮罩層、按下 ESC 鍵觸發(fā)關(guān)閉時(shí), Promise reject 回調(diào)和 callback 回調(diào)的參數(shù)均為 ‘cancel’ (普通彈出框中的點(diǎn)擊取消時(shí)的回調(diào)參數(shù))。

有時(shí)候,兩個(gè)按鈕都需要執(zhí)行觸發(fā)動(dòng)作,如下:

this.$confirm(`審核通過(guò)?`, '提示', {
        distinguishCancelAndClose: true,
        confirmButtonText: '通過(guò)',
        cancelButtonText: '不通過(guò)',
        type: 'warning'
      }).then(() => {
        console.log('確定操作')
      }).catch(action => {
        // 判斷是 cancel (自定義的取消) 還是 close (關(guān)閉彈窗)
        if (action === 'cancel') {
          noPassAudit({ id: id }).then(res => {
            if (res.data.code === 100) {
              this.$message({ type: 'success', message: '操作成功!' })
              this.getTableData()
            } else {
              this.$message({ type: 'error', message: res.data.msg })
              this.getTableData()
            }
          })
        }
})

頁(yè)面效果:

如果將 distinguishCancelAndClose 屬性設(shè)置為 true ,則當(dāng)用戶點(diǎn)擊取消按鈕觸發(fā)取消和點(diǎn)擊關(guān)閉按鈕或遮罩層、按下 ESC 鍵觸發(fā)關(guān)閉時(shí),兩種行為的參數(shù)分別為 ‘cancel’ ‘close’ ,這樣就可以在 catch 中拿到回調(diào)參數(shù) action 進(jìn)行判斷做什么操作了。

注意:如果沒(méi)有設(shè)置 distinguishCancelAndClose true ,則兩種行為都默認(rèn)為取消。

Vue TypeError: this.$confirm is not a function

錯(cuò)誤

在使用element ui,采用局部引入時(shí)候,

報(bào)錯(cuò) TypeError: this.$confirm is not a function

因?yàn)闆](méi)有在vue的實(shí)例上掛載confirm和message導(dǎo)致的報(bào)錯(cuò)

解決方案

修改element.js文件:

1 引入messageBox 插件

import {MessageBox} from ‘element-ui'

2 在vue 的原型對(duì)象上掛載confirm

Vue.prototype.$confirm = MessageBox.confirm

如下圖所示:

以后就可以放心的在vue中的任何文件使用this.confirm或者this.message了。

比如:你想用MessageBox中的confirm方法,現(xiàn)在可以這樣用:

<template>
  <div>
    <el-button type="text" @click="dialogVisible = true">點(diǎn)擊打開(kāi) Dialog</el-button>
    <el-dialog
      title="提示"
      :visible.sync="dialogVisible"
      width="30%"
      :before-close="handleClose">
      <span>這是一段信息</span>
      <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="dialogVisible = false">確 定</el-button>
  </span>
    </el-dialog>
  </div>
</template>
<script>
  export default {
    data () {
      return {
        dialogVisible: false
      }
    },
    methods: {
      handleClose (done) {
        const _this = this
        _this.$confirm('確認(rèn)關(guān)閉?')
          .then(_ => {
            done()
          })
          .catch(_ => {
          })
      }
    }
  }
</script>

總結(jié)

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

相關(guān)文章

最新評(píng)論

龙江县| 孝昌县| 云梦县| 盐津县| 河南省| 光山县| 二连浩特市| 昭苏县| 务川| 绥中县| 万山特区| 屏东市| 长治县| 曲麻莱县| 额尔古纳市| 安国市| 海伦市| 蕲春县| 萝北县| 酒泉市| 沁阳市| 广平县| 巫溪县| 辽源市| 凌海市| 江口县| 南康市| 白城市| 怀化市| 崇礼县| 兴国县| 巴南区| 锡林郭勒盟| 防城港市| 车致| 余江县| 剑阁县| 洛隆县| 辽源市| 诸暨市| 化州市|