Skip to content

Commit 85c7328

Browse files
committed
update vue-router annotations
1 parent af41a7c commit 85c7328

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

Diff for: vue-router-src/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,11 @@ function createHref (base: string, fullPath: string, mode) {
227227
return base ? cleanPath(base + '/' + path) : path
228228
}
229229

230+
/* Vue.use安装插件时候需要暴露的install方法 */
230231
VueRouter.install = install
231232
VueRouter.version = '__VERSION__'
232233

234+
/* 兼容用script标签引用的方法 */
233235
if (inBrowser && window.Vue) {
234236
window.Vue.use(VueRouter)
235237
}

Diff for: vue-router-src/install.js

+11
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,36 @@ import Link from './components/link'
33

44
export let _Vue
55

6+
/* Vue.use安装插件时候需要暴露的install方法 */
67
export function install (Vue) {
8+
9+
/* 判断是否已安装过 */
710
if (install.installed && _Vue === Vue) return
811
install.installed = true
912

13+
/* 保存Vue实例 */
1014
_Vue = Vue
1115

16+
/* 判断是否已定义 */
1217
const isDef = v => v !== undefined
1318

19+
/* 注册router实例 */
1420
const registerInstance = (vm, callVal) => {
1521
let i = vm.$options._parentVnode
1622
if (isDef(i) && isDef(i = i.data) && isDef(i = i.registerRouteInstance)) {
1723
i(vm, callVal)
1824
}
1925
}
2026

27+
/* 混淆进Vue实例,在boforeCreate与destroyed钩子上混淆 */
2128
Vue.mixin({
29+
/* boforeCreate钩子 */
2230
beforeCreate () {
2331
if (isDef(this.$options.router)) {
32+
/* 在option上面存在router则代表是根组件 */
33+
/* 保存跟组件vm */
2434
this._routerRoot = this
35+
/* 保存router */
2536
this._router = this.$options.router
2637
this._router.init(this)
2738
Vue.util.defineReactive(this, '_route', this._router.history.current)

0 commit comments

Comments
 (0)