如何在NUXT插件中显示所有Axios请求的全局加载
我想在全球范围内显示所有Axios请求的
加载
定义
export default function ({ app, $axios, redirect, store }, inject) {
$axios.onRequest(config => {
this.$nuxt.$loading.start()
})
$axios.onError(error => {
this.$nuxt.$loading.finish()
})
}
自 强>在这里。
那么如何修改此代码?
I want to display my custom loading on all axios request globally
for that I've made a plugin for axios to call it like this
plugins/axios.js
export default function ({ app, $axios, redirect, store }, inject) {
$axios.onRequest(config => {
this.$nuxt.$loading.start()
})
$axios.onError(error => {
this.$nuxt.$loading.finish()
})
}
but It get error because we don't have this here .
so how can I modify this code ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
NUXT加载属性用于跟踪页面加载状态。这是您可以用自定义组件替换的内部组件:
但它与为HTTP请求设置加载状态的功能不同。我推荐您创建一个组件来管理HTTP请求的加载状态,并且可以使用VUEX管理当前加载状态,然后从
axios.js.js
插件中修改商店。然后,您可以管理请求状态:
并且非常简单的示例组件:
您可以将加载条或旋转器设置在此组件内的窗口中显示。
The nuxt loading property is used to track pages load status. This is an internal component that you can replace with custom component:
But it is not the same feature that set a loading status for your HTTP requests. I recomend you to create a component to manage the loading status for your HTTP requests, and you can manage the current loading status with Vuex, and then modify the store from your
axios.js
plugin.Then you Vuex store can manage the request status:
And very simple example component:
You can set a loading bar or spinner to display in your window inside this component.