Request get Failing

Asked

Viewed 23 times

0

Hello, I have a problem that is affecting my development. I am developing an application that uses Axios and Vue.js and I wish to make a first get on a data that will go to a props and in that it presents the following error:

inserir a descrição da imagem aqui

I tried to make several other ways and all fell into this same mistake.

inserir a descrição da imagem aqui

Here’s the image of the code. How do I solve this problem?

1 answer

0


You need to resolve the password before you can use the value. Here is an example:

 async asyncData (context) {
    try {
        const { data } = await context.$axios.$get('/vagas')
        return { vagas: data, errorMessage: '' }
    } catch (e) {
        if (e.response.status === 404 || e.response.status === 400 || e.response.status === 500) {
            const { data } = e.response;
            return { vagas: [], errorMessage: data.errors[0].msg }
        } else if (e.request) {
            return { vagas: [], errorMessage: e.request }
        }
        return { vagas: [], errorMessage: e.message }
    }
}

If necessary I can add more snippets of the code.

If the default cannot be used async/await. You can use . then and .catch. Here is an example.

axios.post('/formulas/create', {
    name: "",
    parts: ""
})
.then(response => { 
    console.log(response)
})
.catch(error => {
    console.log(error)
});
  • Thank you very much, I’ve already solved it differently. 
async created() {
 await this.axios("http://localhost:8000/items")
 .then((response) => (this.items = response.data))
 .catch((err) => console.log(err));
 },


Browser other questions tagged

You are not signed in. Login or sign up in order to post.