How to use async / await in get request using vue + axios?

后端 未结 1 1102
醉酒成梦
醉酒成梦 2021-02-06 08:32

I have the following code and would like to know how I can implement a try / catch with async / await executing the same function:

import Vue from \'vue\'
import         


        
1条回答
  •  执念已碎
    2021-02-06 08:55

    see code below:

    var app = new Vue({
      el: '#app',
      async mounted() {
        try{
          let response = await axios.get('http://localhost:8080/wp-json/api/v1/skills')
          this.skills = response
        }catch(err){
          console.log(err)
        }
      }
    })
    
    
    
    

    0 讨论(0)
提交回复
热议问题