[Vuejs]-How to import a function into a Vue component?

0👍

Your problem is not related to importing function in vue component.

You have to change calling api function to this:

  async mounted() {
    this.isLoading = true;
    const res = await axiosGet("https://jsonplaceholder.typicode.com/users");
    if (res) {
      this.APIusers = res;
    }
    this.isLoading = false;
  }

and api function:

export async function axiosGet(url) {
  try {
    const response = await axios.get(url);
    return response.data;
  } catch (err) {
    console.log(err);
  }
}

here is working deme: https://codesandbox.io/s/hopeful-murdock-xqpws

Leave a comment