[Vuejs]-How should i use .then and .catch in an axios call in Vue JavaScript App?

0๐Ÿ‘

Try this code.

mounted () {
    this.isMounted = true;
    axios
      .get('https://api.coindesk.com/v1/bpi/currentprice.json')
      .then(response => {
        console.log("Response is" + response)
      })
      .catch(error => {
        console.log(error)

      })
  }

or

    mounted () {  
    axios.get('https://api.coindesk.com/v1/bpi/currentprice.json')
              .then(function (response) {
               console.log("Response is" + response)
              }.bind(this))
              .catch(error => {
                console.log(error)
              })
  }

0๐Ÿ‘

I have found the error.
I had activated a mock adpter so every call was handled by this MockAdapter.

var mock = new MockAdapter(axios);

So every call fails if it is not in the mockCalls list.
Is there any way to have a MockAdapter for only some specific calls? For example you have to use two different API and only want to have mocked one of them

Leave a comment