axios 通过async和await实现同步

axios 通过async和await实现同步

function getPage(menuId, url) {
  // 这里要有 return
  return this.$http.get(url, {
    	params: {
      	menuId: menuId
    	}
  }).then((response) => {
    return response.data
  }).catch(function (error) {
    console.log(error);
  })
}

async function addTab(component, title, menuId, url) {
  page = await this.getPage(menuId, url);
}

// 调用 addTab 的时候就会等 getPage() 调用完成后才会结束
addTab(...)
posted @ 2021-01-23 23:02  GetcharZp  阅读(135)  评论(0编辑  收藏  举报