Thanks to visit codestin.com
Credit goes to github.com

Skip to content

封装axios时,关于路由跳转login,可以有更好的优化 #29

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

Open
wgxu opened this issue Feb 24, 2020 · 2 comments
Open

封装axios时,关于路由跳转login,可以有更好的优化 #29

wgxu opened this issue Feb 24, 2020 · 2 comments

Comments

@wgxu
Copy link

wgxu commented Feb 24, 2020

在你的src/config/httpConfig.js中,关于超时等状态码判断时,如非200状态码,看跳转到login路由。 您的代码思路没有问题,通过页面刷新和main.js中的路由守卫来判断; 但是呢,页面会有一个重新加载的问题,也是页面抖动。

优化方案: 在httpConfig.js中引入router路由,因此httpConfig.js属于工具类,无法直接应用router。 可在main.js中,把route 直接挂在到window对象上。vue-cli3 底层已经不是单例模式,所以这种改动的弊端是多页面入口时,不适用。 单页面时,路由跳转将会非常顺畅,无需加载抖动

@crush2020
Copy link

为什么一直登陆不上去呢?

@yuanshuai007
Copy link

setTimeout(() => {
window.location.reload()
}, 1000)
你说的是这段代吗吧,改成router.push()
好像是更好一点

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

3 participants