UNPKG

1.12 kBJavaScriptView Raw
1/*
2 * 根据页面的配置,实例化vue对象
3 */
4
5import Vue from 'vue'
6import VueRouter from 'vue-router'
7import { configRouter } from 'utils/configRouter'
8import RoutedApp from 'components/routed-app'
9import ElementUI from 'element-ui'
10import VueI18n from 'vue-i18n'
11
12Vue.use(VueI18n)
13
14/*
15 * @route 页面的路由配置
16 * @store 页面的数据仓库
17 * @el 根节点选择器
18 */
19module.exports = function(opts) {
20 const { route, store, el, component, i18n } = opts
21 Vue.use(ElementUI, {
22 i18n: (key, value) => i18n.t(key, value)
23 })
24 // 如果定义了路由配置,则用routed-app作为根组件
25 if (route) {
26 Vue.use(VueRouter)
27 const transition = route.transition === undefined ? true : !!route.transition
28 configRouter(route).then(router => {
29 const app = new Vue({ template: `<App :animate=${transition}></App>`, components: { App: RoutedApp }, router, store, i18n })
30 app.$mount(el || 'app')
31 })
32 } else {
33 // 否则使用app作为根组件
34 const app = new Vue({ template: '<App/>', components: { App: component }, store, i18n })
35 app.$mount(el || 'app')
36 }
37}