vue登录注册及token验证
// router.js
import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)
const routes = [
{
path: '/',
component: require('./views/Home'),
meta: {
requiresAuth: true
}
},
]
const router = new VueRouter({
routes: routes
})
router.beforeEach((to, from, next) => {
let token = window.localStorage.getItem('token')
if (to.matched.some(record => record.meta.requiresAuth) && (!token || token === null)) {
next({
path: '/login',
query: { redirect: to.fullPath }
})
} else {
next()
}
})
export default router
<script>
// App.vue
export default {
watch:{
'$route':function(to,from){
let token = window.localStorage.getItem('token');
if (to.matched.some(record => record.meta.requiresAuth) && (!token || token === null)) {
next({
path: '/login',
query: { redirect: to.fullPath }
})
} else {
next()
}
}
}
}
</script>
最新文章
- 解决Maven工程中报 Missing artifact jdk.tools:jdk.tools:
- 百度编辑器UEditor常用设置函数大全
- 调试 zeromq 发现 accept 死循环
- guzzle调用失败-缺少guzzle
- HTML5 模拟现实物理效果,感受 Web 技术魅力
- oracle 空间数据库说明
- IOS中用UIStoryBoard类初始化/跳转控制器
- 又爱又恨的BOOTSTRAP
- hdu 4608 I-number 大整数
- NSAttributedString in Swift
- Python开发【字符串格式化篇】
- Taro之使用百度地图
- jmeter性能测试入门
- [Mockito] Spring Unit Testing with Mockito
- mvc 前端校验
- 下载安装windows版Redis
- 2019.01.21 洛谷P3919 【模板】可持久化数组(主席树)
- Lerning Entity Framework 6 ------ Defining Relationships
- 【LibreOJ】#6392. 「THUPC2018」密码学第三次小作业 / Rsa 扩展欧几里得算法
- 哈,今天终于在电脑上吧oracle给装上了