路由缓存
<!-- keep-alive表示该标签内的组件会缓存数据,切走又切换回来时会保存之前留下的讯息,include表示只保存某个路由的数据 -->
<!--注意News为组件名!!!而非路由规则里的路由名-->
<keep-alive include="News">
<router-view></router-view>
</keep-alive>
1
2
3
4
5
2
3
4
5
路由器router上的前进后退方法
<template>
<div>
<div class="col-xs-offset-2 col-xs-8">
<div class="page-header"><h2>Vue Router Demo</h2></div>
<button @click="toBack">后退</button
><button @click="toForward">前进</button
><button @click="toGo">go操作</button>
</div>
</div>
</template>
<script>
export default {
name: "Banner",
methods: {
toBack() {
this.$router.back();
},
toForward() {
this.$router.forward();
},
toGo() {
//go操作既可以前进也可以后退,数字为正即前进,为负即后退,下面表示前进两步
this.$router.go(2);
},
},
};
</script>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28