异步接口请求多个优化写法

async init() {
    
    
      // 数据字典:库区号
      await this.$http
        .get("/api/ms/api/getlist1")
        .then((res) => {
    
    
          this.stockNo = res.data.map((ele) => {
    
    
            return {
    
     value: ele.stockId, label: ele.stockName };
          });
        });

      this.$http.get("/api/ms/api/getlist2").then((res) => {
    
    
        this.tableData = res.data;

      });
    },

使用async await语法糖,可以避免出现回调地域

猜你喜欢

转载自blog.csdn.net/qq_45989814/article/details/123142944