[Vuejs]-Execute custom functions one after another – Callback logic in Vue.js

2πŸ‘

βœ…

If you return the axios call from your ApiLogin function:

function ApiLogin(data) {
  const url = `${BASE_URL}/authenticate`
  return axios.post(url, data)
}

You could then handle the response in your component using then and console log from there:

methods: {
  ProcessLogin() {
    ApiLogin(this.data)
      .then(res => console.log(res))
      .catch(err => console.log(err))
  }
}

…or with async/await:

methods: {
  ProcessLogin: async function() {
    try {
      var status = await ApiLogin(this.data)
      console.log(status)
    }
    catch(err) {
      console.log(err)
    }
  }
}
πŸ‘€Steve Holgado

Leave a comment