小编wDr*_*rik的帖子

如何在使用vue + axios的get请求中使用async/await?

我有以下代码,并想知道如何使用执行相同功能的async/await实现try/catch:

import Vue from 'vue'
import axios from 'axios'

new Vue({
  el: '#app',
  data: {
    skills: [],
  },
  mounted() {
    axios
      .get('http://localhost:8080/wp-json/api/v1/skills')
      .then(response => {
        this.skills = response
      }).catch(err => (console.log(err)))
  }
})
Run Code Online (Sandbox Code Playgroud)

谢谢!

async-await axios vuejs2

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

async-await ×1

axios ×1

vuejs2 ×1