0

My server Api response is like this :-

{"data":{"databases":["rohit_one_test"]},"error":null,"success":true}

I'm using axios with vue js to make the call like this.

//axiosget function

import axios from 'axios';

export function axiosGet (url) {
  return axios.get(url,{ headers: {'Authorization': 'Basic token'}})
    .then(function (response) {
        return response.data.data;
    })
    .catch(function (error) {
        return 'An error occured..' + error;
    })
}

i'm calling it somewhere else like this :-

showdblist(){
      this.url=API_LOCATION+"/tools/mysql/resources/databases/"+this.domain;
      this.dbs=axiosGet(this.url);
      console.log(this.dbs);

}

when i log the dbs variable it has something like this.

screen shot here :--https://prnt.sc/kmaxbq

my question is how can i access the name of my databases in the dbs variable ?

1 Answer 1

2

Well it's a promise being returned, so your return from within the promise resolve does nothing. Instead, treat it as a promise that's returned, and resolve from it like:

async showdblist() {
    this.dbs = await axiosGet(this.url)
    // now this.dbs is correct
}

If you can't use async/await just treat it like a regular promise:

axiosGet(this.url)
    .then((response) => {
        this.dbs = response.data.data
    })
Sign up to request clarification or add additional context in comments.

2 Comments

Is there a preferred, efficient way or either of the above two is good to use? Thanks
@Aseem You just choose the pattern that you like most.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.