Skip to content

Commit 51b18b1

Browse files
committed
完善边界条件处理
1 parent 41866d7 commit 51b18b1

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

src/activator.ts

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ const HOOK_KEYS: { [index: string]: boolean } = Object.freeze({
1515
onError: true
1616
})
1717

18+
const defaultAppComponent = { name: 'app', render: (h: any) => h('router-view') }
19+
const defaultAppElement = '#app'
20+
1821
function addVuexModules(modular: Modular) {
1922
const application = modular.getApplication()
2023
const vuexAlong: any = {
@@ -137,23 +140,26 @@ function addRouterHooks(modular: Modular) {
137140
}
138141

139142
function createVueInstance(modular: Modular) {
140-
// 处理 vue.app
141-
const app = modular.getExtension('vue.app')
142-
const component = app.component || { name: 'app', render: (h: any) => h('router-view') }
143-
const options: any = {
144-
router,
145-
store,
146-
render: (h: any) => h(component)
147-
}
148-
// 处理 vue.options
149-
const vueOptions = modular.getExtension('vue.options')
150-
if (vueOptions !== null) {
151-
options.mixins = vueOptions
152-
}
153-
const vm = new Vue(options)
154-
const element: string = app.element || '#app'
155-
vm.$mount(element)
156-
modular.setAttribute('vue.instance', vm)
143+
// 处理 vue.app
144+
let app = modular.getExtension('vue.app')
145+
if (app === undefined) {
146+
app = { component: defaultAppComponent, element: defaultAppElement }
147+
}
148+
const component = app.component || defaultAppComponent
149+
const options: any = {
150+
router,
151+
store,
152+
render: (h: any) => h(component)
153+
}
154+
// 处理 vue.options
155+
const vueOptions = modular.getExtension('vue.options')
156+
if (vueOptions !== null) {
157+
options.mixins = vueOptions
158+
}
159+
const vm = new Vue(options)
160+
const element: string = app.element || defaultAppElement
161+
vm.$mount(element)
162+
modular.setAttribute('vue.instance', vm)
157163
}
158164

159165
const activator: Activator = {

0 commit comments

Comments
 (0)