router--index.js
router.beforeEach((to,from,next)=>{
let nextRoute = ['Payment','Cart','Path','Order','pathIndex','path-list'];
//是否是登录中
let userInfo = JSON.parse( localStorage.getItem('teaUserInfo') );
//当前进入的页面,是不是需要验证哪些页面
if( nextRoute.indexOf( to.name ) >= 0 ){
if( !userInfo ){
router.push('/login');
}
}
next();
})
路由版本问题
解决
const originalPush = VueRouter.prototype.push
const originalReplace = VueRouter.prototype.replace
// push
VueRouter.prototype.push = function push (location, onResolve, onReject) {
if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
return originalPush.call(this, location).catch(err => err)
}
// replace
VueRouter.prototype.replace = function push (location, onResolve, onReject) {
if (onResolve || onReject) return originalReplace.call(this, location, onResolve, onReject)
return originalReplace.call(this, location).catch(err => err)
}
token
后台 db---userSql.js
token设置成60s
//生成token
let token = jwt.sign(payload, secret, {
expiresIn: 60,
});
index.js
function getTimeToken(exp) {
let getTime = parseInt(new Date().getTime() / 1000);
if (getTime - exp > 60) {
return true;
}
}