HBuilder编译uniapp 报错Module Error :Errors compiling template:(最终根本原因)

代码区域

报错信息:


Module Error (from ./node_modules/@dcloudio/vue-cli-plugin-uni/packages/vue-loader/lib/loaders/templateLoader.js):
22:15:20.654 (Emitted value instead of an instance of Error) 
22:15:20.654   Errors compiling template:
22:15:20.660   Component template should contain exactly one root element. If you are using v-if on multiple elements, use v-else-if to chain them instead.
22:15:20.669   3  |      
22:15:20.680   4  |      
22:15:20.681   5  |  
22:15:20.690      |          
22:15:20.691   6  |  房源列表
22:15:20.697      |  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22:15:20.698   7  |  
22:15:20.703      |  
22:15:20.709  at D:\Documents\HBuilderProjects\fangzuzu-uniceshi\pages\index\index.vue:0
 

通过报错信息,我们可以定位错误的代码位置。

HBuilder编译uniapp 报错Module Error :Errors compiling template:(最终根本原因)_第1张图片

 按照之前学习HTML和微信小程序的思路,就算能定位错误区域,我还是无法找到具体的错误原因。

首先:把标签改为也还是报同样的错误;

然后:就去uniapp官网查看文档,还是没能找出原因。

再者:在网上搜索问题(uniapp 报错Module Error :Errors compiling template:)还是没有找到自己想要的结果的。

最后想到了,uniappp虽然和微信小程序大体是一样的,但是用的有vue语法。这个我是没有看过的,就去vue语法文档看了一下vue3基础;果真被我找到了原因!!!

HBuilder编译uniapp 报错Module Error :Errors compiling template:(最终根本原因)_第2张图片

 注意:(在uniapp中必须有一个view,且只能有一个根view;所有内容写在这个view下面)

接着我就把错误的那行代码放到第一个view中,终于编译成功,没有报错了。HBuilder编译uniapp 报错Module Error :Errors compiling template:(最终根本原因)_第3张图片

 

你可能感兴趣的:(uni-app,vue.js,builder模式,前端)