mirror of
https://github.com/xxxsf/vue3-h5-template.git
synced 2025-04-06 05:23:46 +08:00
1
This commit is contained in:
parent
cc3125026a
commit
e5b0985b45
@ -29,12 +29,10 @@ module.exports = function(router){
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
window.routeList=[];
|
||||
|
||||
router.beforeEach(function(transition){
|
||||
console.log('before---------------');
|
||||
|
||||
//可以通过在路由中的自定义字段来验证用户是否需要登陆
|
||||
// console.log('通过配置路由中自定义的字段验证是否需要登陆');
|
||||
if(transition.to.auth){
|
||||
@ -48,37 +46,6 @@ module.exports = function(router){
|
||||
transition.next();
|
||||
}
|
||||
|
||||
|
||||
|
||||
//如果是中止,这里可以判断用户登录
|
||||
//if(transition.to.path === '/forbidden'){
|
||||
if(transition.to.name == 'forbidden'){
|
||||
router.app.authenticating = true
|
||||
setTimeout(function(){
|
||||
router.app.authenticating = false
|
||||
alert('此路由在全局中设置为中止');
|
||||
transition.abort();
|
||||
},1500);
|
||||
}
|
||||
|
||||
if(routeList.length > 1 && transition.to.name==routeList[routeList.length-2]['name']){
|
||||
router.app.effect='back';
|
||||
routeList.splice(routeList.length-1,1);
|
||||
console.log(routeList);
|
||||
} else {
|
||||
router.app.effect='fade';
|
||||
routeList.push({
|
||||
name : transition.to.name,
|
||||
path : transition.to.path,
|
||||
query : transition.to.query,
|
||||
params : transition.to.params,
|
||||
timer: +new Date
|
||||
});
|
||||
}
|
||||
|
||||
// setTimeout(function(){
|
||||
// transition.next();
|
||||
// },00);
|
||||
});
|
||||
|
||||
//可以记录访问路径
|
||||
|
@ -14,13 +14,19 @@
|
||||
<div class="index">
|
||||
<h2>vue-router 介绍:</h2>
|
||||
<a class="router-link" href="http://router.vuejs.org/zh-cn/" target="_blank">点击这里</a>
|
||||
|
||||
<mt-cell title="标题文字"></mt-cell>
|
||||
<mt-cell title="标题文字" value="说明文字"></mt-cell>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
||||
var lifecycle = []; //为了描述生命周期, 在 canActivate 阶段 还没有 this.lifecycle
|
||||
|
||||
import Vue from 'vue'
|
||||
import { Cell } from 'mint-ui';
|
||||
Vue.component(Cell.name, Cell);
|
||||
|
||||
module.exports = {
|
||||
//props: ['父组建传的值'],
|
||||
data:function(){
|
||||
@ -35,13 +41,13 @@
|
||||
//waitForData: true, //数据加载完毕后再切换试图,也就是 点击之后先没反应,然后数据加载完,再出发过渡效果
|
||||
canActivate:function(transition){
|
||||
//canActivate阶段,可以做一些用户验证的事情
|
||||
lifecycle.push("route.canActivate <a href='http://vuejs.github.io/vue-router/zh-cn/pipeline/can-activate.html'>在验证阶段,当一个组件将要被切入的时候被调用。</a>");
|
||||
console.log(1);
|
||||
return true;
|
||||
},
|
||||
activate:function(transition){
|
||||
//console.log('active');
|
||||
this.lifecycle.push("route.activate <a href='http://vuejs.github.io/vue-router/zh-cn/pipeline/data.html'>在激活阶段被调用,在 activate 被断定( resolved ,指该函数返回的 promise 被 resolve )。用于加载和设置当前组件的数据。</a>");
|
||||
// this.$root.$set('header',this.title);
|
||||
//this.$root.$set('header',this.title);
|
||||
|
||||
transition.next();
|
||||
//此方法结束后,api会调用afterActivate 方法
|
||||
|
@ -1,6 +1,7 @@
|
||||
<template>
|
||||
<div>
|
||||
Login page
|
||||
看来汝方才点击的页面需要登录才能看呀~
|
||||
页面还没写,你自己看着搞搞把。
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user