[Vue warn]: Failed to mount component: template or render function not defined. 错误解决方法

时间:2023-03-10 01:34:43
[Vue warn]: Failed to mount component: template or render function not defined. 错误解决方法

解决方法
import Vue from "vue"; 默认引入的文件是 vue/dist/vue.runtime.common.js。这个可以在node_modules/vue/package.json文件里面查到。package文件的main选项指定了默认执行的文件。关键的package.json代码如下:

[Vue warn]: Failed to mount component: template or render function not defined. 错误解决方法

这个代码说明了 vue.runtime.common.js 文件不含编译器,因此不支持template选项。我们使用Webpack和template选项的话,可以使用vue.common.js文件。vue.common.js文件包含编译器。所以在main.js中把

[Vue warn]: Failed to mount component: template or render function not defined. 错误解决方法

修改为:

[Vue warn]: Failed to mount component: template or render function not defined. 错误解决方法

这样一来就可以正常使用 vue 文件