• this.$confirm里面使用await异步调取接口数据


    this.$confirm里面使用await

    在this.$comfirm中需要点击确定后进行某些异步操作,如果在方法名上写async的话会直接报错:Can not use keyword 'await' outside an async function (419:23)

    async cancelappointment(item) {
          this.$confirm("确认取消该议程吗?", "取消", {
            confirmButtonText: "确认",
            cancelButtonText: "取消",
            type: "warning"
          })
            .then( () => {
              let params = {};
              params.meeting_id = item.meeting_id;
              params.user_id = this.$store.state.userId;
              params.agenda_id = item.agenda_id;
              params.agenda_type = item.remind_type;
              let result = await this.$store.dispatch(
                "API_conference/cancelMeetingLive",
                params
              );
              if (result.success) {
                this.list = this.list.filter(item => {
                  item.agenda_id != item.agenda_id;
                });
                this.currentData = this.currentData.filter(item => {
                  item.agenda_id != item.agenda_id;
                });
                if (this.currentData.length == 0) {
                  this.timedata.splice(this.current, 1);
                  this.current = 0;
                  // this.timedata=this.timedata.filter(item=>{
                  //   item!=item.day
                  // })
                }
              }
            })
            .catch(() => {});
        }, 
    

    正确的写法是将async写在then中箭头函数的前面 :

    cancelappointment(item) {
            this.$confirm("确认取消该议程吗?", "取消", {
              confirmButtonText: "确认",
              cancelButtonText: "取消",
              type: "warning"
            })
              .then(async () => {
                let params={}
                params.meeting_id=item.meeting_id
                params.user_id=this.$store.state.userId
                params.agenda_id=item.agenda_id
                params.agenda_type=item.remind_type
                let result=await this.$store.dispatch("API_conference/cancelMeetingLive",params)
                if (result.success){
                  this.list=this.list.filter(item=>{
                    item.agenda_id!=item.agenda_id
                  })
                  this.currentData=this.currentData.filter(item=>{
                    item.agenda_id!=item.agenda_id
                  })
                  if (this.currentData.length == 0){
                    this.timedata.splice(this.current,1)
                    this.current=0
                    // this.timedata=this.timedata.filter(item=>{
                    //   item!=item.day
                    // })
                  }
                }
              })
              .catch(() => {});
        }
    
  • 相关阅读:
    -/bin/sh: ./led: not found的解决办法
    s5pv210启动debian出错提示bash: cannot set terminal process group (-1): Inappropriate ioctl for device
    s5pv210 cpu运行debian
    解决qt程序运行时的cannot create Qt for Embedded Linux data directory: /tmp/qtembedded-0出错情形
    easyui datagrid的API
    <% 拼写页面
    easyui编辑editor
    H2数据库介绍
    easyUI的datagrid控件日期列格式化
    oracle取出所有表和视图
  • 原文地址:https://www.cnblogs.com/my466879168/p/13175282.html
Copyright © 2020-2023  润新知