zoukankan      html  css  js  c++  java
  • messageBox的.then改造为async/await写法

    官网提供的写法:

    <template>
      <el-button type="text" @click="open">点击打开 Message Box</el-button>
    </template>
    
    <script>
      export default {
        methods: {
          open() {
            this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(() => {
              this.$message({
                type: 'success',
                message: '删除成功!'
              });
            }).catch(() => {
              this.$message({
                type: 'info',
                message: '已取消删除'
              });          
            });
          }
        }
      }
    </script>
    

    但是不想在.then中写其他方法,改造为同步的async,await写法

    <template>
      <el-button type="text" @click="open">点击打开 Message Box</el-button>
    </template>
    
    <script>
      export default {
        methods: {
          async open() {
            const res = await this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning",
            })
    
            if(res == 'confirm'){
              console.log('执行成功回调')
            }else{
              console.log('执行失败回调')
            }
          },
        }
      }
    </script>
    
  • 相关阅读:
    java 运算符的优先级比较
    Java String类和StringBuffer类的区别
    Java 并发编程
    java构造函数和初始化
    Java 动态绑定
    Java day3
    Java day2
    Java day1
    计算机系统原理之程序是怎么运行的 【转】
    MemberCached 学习上【转】
  • 原文地址:https://www.cnblogs.com/yx1102/p/14770964.html
Copyright © 2011-2022 走看看