gpt4 book ai didi

vue.js - 如何访问 Nuxt.js 中 axios 插件内部的当前 fullPath?

转载 作者:行者123 更新时间:2023-12-02 07:48:39 25 4
gpt4 key购买 nike

我正在尝试从 Axios 的 Nuxt 插件中通过 route.fullPath 获取当前路径。它在一定程度上起作用,但看起来因为它来自上下文,所以它只在页面最初加载时设置路径。如何在 Axios 错误发生时显示当前的 route.fullPath (在任何路线更改之后)?

export default function ({ $axios, store, route, redirect }) {
$axios.onError((error) => {
if (error.response.status === 401) {
store.commit('misc/setRedirect', route.fullPath);

redirect('/sign-in');
}
});
}

最佳答案

这似乎是一个错误,但作为解决方法,您可以通过 app.router.currentRoute 获取当前路线插件的 app 参数:

// plugins/axios.js
export default function ({ $axios, app }) {
$axios.onError(error => {
console.log(error, app.router.currentRoute)
})
}

关于vue.js - 如何访问 Nuxt.js 中 axios 插件内部的当前 fullPath?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58329587/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com