Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Injecting returns a promise and calling api wont work #119

Closed
allestaire opened this issue Nov 21, 2021 · 0 comments
Closed

Injecting returns a promise and calling api wont work #119

allestaire opened this issue Nov 21, 2021 · 0 comments

Comments

@allestaire
Copy link

allestaire commented Nov 21, 2021

Upon checking the API, it returns promise then when I tried to call api it does not work, like there are no network listed on console
after injecting, I tried to console the axios variable but got this response, dont know what is this means
image

import { defineComponent, inject } from 'vue'
...
setup() {
   const axios = inject('axios')
   ...
   axios.get(api) // not working, no logs on the network
}

Axios configuration

app.provide('axios', axios({
  baseURL: 'api/v1',
  headers: {
    // 'Access-Control-Allow-Origin': '*',
    'Authorization': 'Bearer klahdk9817landlkahoaowhd'
  }
}))

Got it working, but have to remove global configuration,
Now my question is how to intialize global config?
axios.defaults.baseURL = 'api/v1'

Thanks for this post #2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant