Vue错误信息解决

在运行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.

出现这个错误的主要原因是:

vue有两种形式的代码 compiler(模板)模式和runtime模式(运行时),vue模块的package.json的main字段默认为runtime模式, 指向了"dist/vue.runtime.common.js"位置

如果你需要在客户端编译模板 (比如传入一个字符串给 template 选项,或挂载到一个元素上并以其 DOM 内部的 HTML 作为模板),就将需要加上编译器,即完整版

当使用 vue-loader 或 vueify 的时候,*.vue 文件内部的模板会在构建时预编译成 JavaScript。你在最终打好的包里实际上是不需要编译器的,所以只用运行时版本即可

 

简单解决方法:

把以下代码:

import Vue from 'vue'

改成:

import Vue from 'vue/dist/vue.esm.js'

 

posted @ 2019-04-20 20:58  Michelyuan  阅读(1693)  评论(0编辑  收藏  举报