Fe-interview: [vue] 如果将axios异步请求同步化处理?

Created on 20 Jun 2019  ·  3Comments  ·  Source: haizlin/fe-interview

[vue] 如果将axios异步请求同步化处理?

vue

Most helpful comment

// 统一处理axios请求
    async getHistoryData (data) {
      try {
        let res = await axios.get('/api/survey/list/', {
          params: data
        })
        this.tableData = res.data.result
        this.totalData = res.data.count
      } catch (err) {
        console.log(err)
        alert('请求出错!')
      }
    }
  }

All 3 comments

async ,await

// 统一处理axios请求
    async getHistoryData (data) {
      try {
        let res = await axios.get('/api/survey/list/', {
          params: data
        })
        this.tableData = res.data.result
        this.totalData = res.data.count
      } catch (err) {
        console.log(err)
        alert('请求出错!')
      }
    }
  }

async ,await
Generator函数
回调里面写回调

Was this page helpful?
0 / 5 - 0 ratings