出现的问题
在引入earth-ui到现有的vue项目中,出现
1 | [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. |
主要是因为代码中动态生成了template
选项;
如何解决
- 使用运行时版本
本次项目主要使用vue-cli3创建,因此首先在vue.config.js
文件中配置然后确认1
2
3
4
5module.exports = {
...
runtimeCompiler: true
...
}main.js
里使用render
渲染:1
2
3
4new Vue({
router,
render: h => h(App),
}).$mount('#app') - 使用完整版本
1
2
3
4
5
6
7
8module.exports = {
// ...
resolve: {
alias: {
'vue$': 'vue/dist/vue.esm.js' // 用 webpack 1 时需用 'vue/dist/vue.common.js'
}
}
}参考文章
- vue.js官网 https://cn.vuejs.org/v2/guide/
- Fix “[Vue warn]: You are using the runtime-only build of Vue”