-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathbase-example.html
172 lines (157 loc) · 5 KB
/
base-example.html
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<!-- <script src="/Users/wxkmac/Documents/Github/core/packages/vue/dist/vue.global.js"></script> -->
<script src="../debug3/vue3.js"></script>
<script src="../debug3/vue-router4.js"></script>
<script src="../dist/index.js"></script>
</head>
<body>
<div id="app">
<h1>Hello App!</h1>
<router-view v-slot="{ Component }">
<!-- <keep-alive :max="1">
<component :is="Component"/>
</keep-alive> -->
<stack-keep-alive v-slot='{ key }'>
<component :is="Component" :key='key'/>
</stack-keep-alive>
</router-view>
</div>
<script>
const Keep = {
name: 'keep',
template: `
<router-view v-slot="{ Component }">
<stack-keep-alive v-slot='{ key }'>
<component :is="Component" :key='key'/>
</stack-keep-alive>
</router-view>`
,
setup(){
const route = VueRouter.useRoute();
const defaultActive = Vue.computed(() => route.fullPath);
return {
defaultActive
}
}
}
const Foo = {
name: 'foo',
template: '<div><p>this is foo page {{a}}</p><router-link to="/bar">Go to Bar</router-link></div>',
data() {
return {
b: 20
}
},
beforeCreate() {
console.log(this)
// console.log(this.$.ctx === this)
console.log("foo beforeCreate")
},
setup(props) {
const a = 10
return {
a
}
},
unmounted() {
console.log("foo unmounted")
},
deactivated() {
console.log("foo deactivate")
},
activated() {
console.log("foo activate")
},
}
const Bar = {
name: 'bar',
props: ['test_prop'],
data() {
return { 'test_data': 'help', date: new Date()}
},
setup(props) {
const a = []
for (let index = 0; index < 1000; index++) {
a.push(new Date())
}
return {
a
}
},
template: '<div><p>this is bar page</p><router-link to="/baz">Go to Baz</router-link></div>' ,
beforeCreate() {
console.log("bar beforeCreate")
},
unmounted() {
console.log("bar unmounted")
},
deactivated() {
console.log("bar deactivate")
},
activated() {
console.log("bar activate")
},
}
const Baz = {
name: 'baz',
template: '<div><p>this is baz page</p><div @click="goback">goBack</div><router-link to="/foo">Go to Foo</router-link></div>',
methods:{
goback(){
this.$router.back();
}
},
unmounted() {
console.log("baz unmounted")
},
}
const Home = {
name: 'home',
template: '<div><p>this is home page</p><div @click="goback">goBack</div><router-link to="/foo">Go to Foo</router-link></div>',
methods:{
goback(){
this.$router.back();
}
},
deactivated() {
console.log("home deactivate")
},
activated() {
console.log("home activate")
},
unmounted() {
console.log("home unmounted")
},
}
const routes = [
{ path: '/', component: Home },
{ path: '/foo', component: Foo },
{ path: '/bar', component: Bar },
{ path: '/baz', component: Baz }
]
// const router = new VueRouter({
// routes,
// mode:'hash',
// })
const router = VueRouter.createRouter({
// 4. 内部提供了 history 模式的实现。为了简单起见,我们在这里使用 hash 模式。
history: VueRouter.createWebHashHistory(),
routes, // `routes: routes` 的缩写
})
// const app = new Vue({
// router
// }).$mount('#app')
const app = Vue.createApp({})
//确保 _use_ 路由实例使
//整个应用支持路由。
app.use(StackKeepAlive)
// createHelper({Vue: app, router})
app.use(router)
app.mount('#app')
</script>
</body>
</html>