阅读背景:

vue 中使用 async/await 将 axios 异步请求同步化处理

来源:互联网 

1. axios 常规用法:

export default {
  name: 'Historys',
  data() {
    return { 
      totalData: 0,  
      tableData: []
    }
  },
  created () {
    this.getHistoryData()
  },
  methods: { 
    handleClick (tab) {
      let data = {
        status: tab.name,
        name: this.formInline.user,
        cid: this.formInline.identity,
        start_time: this.formInline.dateTime ? this.formInline.dateTime[0] : '',
        end_time: this.formInline.dateTime ? this.formInline.dateTime[1] : ''
      }
      this.getHistoryData()
    },
    // 统一处理axios请求
    getHistoryData (data) { 
      axios.get('/api/survey/list/', {
        params: data
      }).then((res) => {
        console.log(res)
        this.tableData = res.data.result
        this.totalData = res.data.count
      }).catch((err) => {
        console.log(err)
        alert('请求出错!')
      })
    }
  }
}export default {
  name: 'Hist



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: