当前位置:网站首页>How to achieve the top progress bar effect in background management projects
How to achieve the top progress bar effect in background management projects
2022-07-02 10:09:00 【Capricorn**】
First installation
npm i nprogress
# perhaps
yarn add nprogress
Besides the function , The progress bar also has styles , The first thing you need to do is main.js Introducing style
import 'nprogress/nprogress.css'
stay router/index.js in , Introduce the module
import nprogress from 'nprogress'
In the global front guard Start the route before jumping nprogress
router.beforeEach((to,from,next)=>{
// Turn on before route jump
nprogress.start()
// As long as the access is not login /login Jump to /login
if(to.path === '/login'){
next()
}else{
// Get localstorage Medium token
const token = localStorage.getItem('token')
if(token){
// If it's not login But I have logged in Then jump normally
next()
}else{
next('/login')
}
}
})
After the route jump ends ( Route post hook ) call done Method end
// Route post hook
router.afterEach(()=>{
// After the route jump is completed The progress bar ends
nprogress.done()
})
Such as the following effect
边栏推荐
- Judging right triangle in C language
- 2837xd 代码生成——StateFlow(3)
- Brief analysis of edgedb architecture
- What is the relationship between realizing page watermarking and mutationobserver?
- Because of hard work, the fruit goes with fate
- 2837xd 代码生成——补充(2)
- ICLR 2022: how does AI recognize "things I haven't seen"?
- Inverter Simulink model -- processor in the loop test (PIL)
- [illusory] weapon slot: pick up weapons
- 2837xd Code Generation - stateflow (4)
猜你喜欢
随机推荐
Web security and defense
Alibaba cloud SMS service
2837xd code generation - Supplement (3)
三相逆变器离网控制——PR控制
Tinyxml2 reading and modifying files
Personal experience & blog status
UE4夜间打光笔记
Project practice, redis cluster technology learning (VII)
Project practice, redis cluster technology learning (6)
UE4 night lighting notes
How does {} prevent SQL injection? What is its underlying principle?
【虚幻】按键开门蓝图笔记
2837xd代码生成模块学习(4)——idle_task、Simulink Coder
[ue5] blueprint making simple mine tutorial
Junit5 支持suite的方法
Memories of a chat
Large neural networks may be beginning to realize: the chief scientist of openai leads to controversy, and everyone quarrels
【UE5】动画重定向:如何将幻塔人物导入进游戏玩耍
ue虚幻引擎程序化植物生成器设置——如何快速生成大片森林
三相并网逆变器PI控制——离网模式