-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[vue] 你有封装过axios吗?主要是封装哪方面的? #303
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
Labels
vue
vue
Comments
统一上下文请求路径、统一超时时间、统一错误处理和拦截发送请求用于添加token |
封装处理配置(路径、时间、token)、统一管理接口、错误处理、不同形式的请求、消息提示、loading等。 |
用Promise在封装一次axios,并统一baseURL,超时时间,请求拦截,响应拦截处理,统一管理接口,批量导出。 |
如何封装axios
在需要使用Axios的地方,可以直接引入axios.js文件并使用它发送请求。
在Vue应用的入口文件中,通过Vue.use()方法安装插件。
然后,在组件中就可以通过this.$axios来使用Axios发送请求。
通过以上方式,可以在Vue中封装Axios,使其在项目中更方便地使用。在模块化的方式中,直接引入axios.js文件即可使用Axios,而在插件方式中,则可以通过this.$axios在Vue实例和组件中使用Axios。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
[vue] 你有封装过axios吗?主要是封装哪方面的?
The text was updated successfully, but these errors were encountered: