为什么Vue在语言路由中抛出错误?

时间:2018-11-30 09:07:21

标签: vue.js vue-router

我使用vue/cli 3vue create hello-world创建了一个新的Vue项目,然后我对所有要求的选项都说是。

我想为每个路由角色添加lang前缀。

因此,唯一的文件已从router.ts更改为by this example

export default new Router({
  mode: 'history',
  base: process.env.BASE_URL,
  routes: [
    {
      path: '/',
      name: 'home',
      component: Home
    },
    {
      path: '/:lang',
      component: {
        template: '<router-view></router-view>'
      },
      children: [
        {
          path: 'about',
          name: 'about',
          // route level code-splitting
          // this generates a separate chunk (about.[hash].js) for this route
          // which is lazy-loaded when the route is visited.
          component: () => import(/* webpackChunkName: "about" */ './views/About.vue')
        }
      ]
    }
  ]
});

但是在运行时出现错误:

[Vue warn]: You are using the runtime-only build of Vue where the template compiler is not available. Either pre-compile the templates into render functions, or use the compiler-included build.

found in

---> <Anonymous>
       <App> at src/App.vue
         <Root>

此错误消息是什么意思?以及如何解决?

1 个答案:

答案 0 :(得分:1)

对于如何在编译时不生成渲染功能,我没有任何解释,但是您可以在changing the runtimecompiler option中将完整的vue + compiler包含在vue.config.js中。