Skip to content

Commit 6e5dc49

Browse files
committed
update vue-router annotations
1 parent 47b387d commit 6e5dc49

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

vue-router-src/components/view.js

+11
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,42 @@ export default {
1515
}
1616
},
1717
render (_, { props, children, parent, data }) {
18+
/* 标记位,标记是route-view组件 */
1819
data.routerView = true
1920

2021
// directly use parent context's createElement() function
2122
// so that components rendered by router-view can resolve named slots
23+
/* 直接使用父组件的createElement函数 */
2224
const h = parent.$createElement
25+
/* props的name,默认'default' */
2326
const name = props.name
27+
/* option中的VueRouter对象 */
2428
const route = parent.$route
29+
/* 在parent上建立一个缓存对象 */
2530
const cache = parent._routerViewCache || (parent._routerViewCache = {})
2631

2732
// determine current view depth, also check to see if the tree
2833
// has been toggled inactive but kept-alive.
34+
/* 记录组件深度 */
2935
let depth = 0
36+
/* 标记是否是待用(非alive状态)) */
3037
let inactive = false
38+
/* _routerRoot中中存放了跟组件的势力,这边循环向上级访问,直到访问到根组件,得到depth深度 */
3139
while (parent && parent._routerRoot !== parent) {
3240
if (parent.$vnode && parent.$vnode.data.routerView) {
3341
depth++
3442
}
43+
/* 如果_inactive为true,代表是在keep-alive中且是待用(非alive状态) */
3544
if (parent._inactive) {
3645
inactive = true
3746
}
3847
parent = parent.$parent
3948
}
49+
/* 存放route-view组件的深度 */
4050
data.routerViewDepth = depth
4151

4252
// render previous view if the tree is inactive and kept-alive
53+
/* 如果inactive为true说明在keep-alive组件中,直接从缓存中取 */
4354
if (inactive) {
4455
return h(cache[name], data, children)
4556
}

0 commit comments

Comments
 (0)