未捕获的 ReferenceError:then 未在 Element Ui Plus 中定义

问题描述

我正在使用 vue3element-ui-plus 来构建项目。

但是当我尝试在 MessageBox 中使用 element-ui-plus 时,出现错误 Uncaught ReferenceError: then is not defined

MessageBox外,其他功能都很好。

这是我的代码。并且请参考handleDelete函数

    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
    <script>
        const app ={
            el: '#app',data(){
                return {
                    pagination: {
                        currentPage: 1,pageSize: 10,total: 0,queryString: null
                    },formData: {},}
            },created() {
                this.findPage();
            },methods: {
                findPage() {
                    var param = {
                        currentPage: this.pagination.queryString == null ? this.pagination.currentPage : 1,pageSize: this.pagination.pageSize,queryString: this.pagination.queryString
                    };
                    axios.post("/checkitem/findPage.do",param).then(res => {
                        this.pagination.total = res.data.total;
                        this.dataList = res.data.rows;
                    });

                },resetForm() {
                    this.formData = {};
                },handleDelete(row) {
                    this.$confirm("Do you want to delete the record?","Warning",{
                        confirmButtonText: "Yes",cancelButtonText: "No",type: "warning"
                    }).then(() => {
                        console.log("delete record");
                        axios.get("/checkitem/delete.do?id="+row.id).then(res => {

                        });
                    }).catch(() => {

                    });


                }
            }
        };
        Vue.createApp(app).use(ElementPlus).mount("#app");
<script>

解决方法

@Oliver 你可以试着让你的函数 async。见下文

async handleDelete(row) {
  try {
      await this.$confirm("Do you want to delete the record?","Warning",{
        confirmButtonText: "Yes",cancelButtonText: "No",type: "warning"
    })
    console.log("delete record")
    axios.get("/checkitem/delete.do?id="+row.id)
  } catch (error) {
    // handle error
  } finally {
    // something else if you need
  }
})

问题是,您是否打算在触发执行删除之前等待用户确认/取消点击?