[Vuejs]-What's wrong with my axios

0👍

The problem is that you are trying to return the value of the request from the then block. But you use await. So try this:

export default async(url = '', type = 'GET') => {
    ...
    if (type == 'GET') {
        try {
            var res = await axios.get(url)
            console.log(res.data)
            return res
        } catch (error) {
            console.log('Some error...', error)
        }
    }
}

[ https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await ]

Leave a comment