下班过目遇到一个错误
[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编译版本不对
解决方案1
build/webpack. .conf.js 并设置vue的alias别名,如下:
resolve: {
alias: {
vue: 'vue/dist/vue.esm.js'
}
}
解决方案2
打开src/main.js修改Vue对象初始化。
new Vue({
el: '#app',
router,
components: { App },
template: '<App/>'
})
改为
new Vue({
el: '#app',
router,
render: h => h(App)
})
原因是,使用 template属性,需要引入带编译器的完整版的vue.esm.js
而如果在.vue文件里面使用
<template>
<div></div>
</template>
< >
export default {
name:'name1',
data() {
return {};
}
};
</ >
这种形式,然后使用import引入,则不需要完整版的vue.esm.js,因为使用vue-loader时 *.vue文件会自动预编译成js。
其实vuejs官网中已有明确说明
其他相关文章:
理顺8个版本vue的区别(https://www.jb51.net/article/147538.htm)
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
继续阅读与本文标签相同的文章
下一篇 :
整理一些计算机基础知识!
-
看懂打印机“红绿灯”,文印轻松上路!
2026-05-15栏目: 教程
-
遛店:新零售万亿市场开启新消费时代
2026-05-15栏目: 教程
-
澳大利亚大学将使用VR和AR技术为学生教授解剖学
2026-05-15栏目: 教程
-
一招分辨小程序类型,避免上当受骗
2026-05-15栏目: 教程
-
英飞凌雷达技术导入Google Pixel 4 实现手势控制
2026-05-15栏目: 教程
