You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here is an example. Create a plugin-http.js file in a plugins directory:
importaxiosfrom'axios'functioninterceptResponse(response){// something}functioninterceptRequest(config){// something}axios.interceptors.request.use(interceptRequest)axios.interceptors.response.use(interceptResponse,// catch errors)constapi={install(Vue){Vue.prototype.$api=axios.create({baseURL: `/api/`,headers: {Authorization: 'Bearer {token}'}})}}// Automatic installation if Vue has been added to the global scope.if(typeofwindow!=='undefined'&&window.Vue){window.Vue.use(api)}exportdefaultapi
axios is a Promise based HTTP client for the browser and node.js.
To add it to Vue make a plugin.
Here is an example. Create a
plugin-http.js
file in a plugins directory:An
index.js
for the plugins directory:In
main.js
install the plugin with:Now you can use the
$api
property on any Vue orthis
object:The text was updated successfully, but these errors were encountered: