uni-app HB格式化会破坏HTML的格式

uni-app HB格式化会破坏HTML的格式

开发环境 版本号 项目创建方式
HbuilderX 3.2.11 -
示例代码:

格式化前:  
`<template>`  
`<view :hover-class="hoverClass" :hover-start-time='hoverStartTime' :hover-stay-time='hoverStayTime'`   
`<!-- #ifndef APP-NVUE && MP-ALIPAY && MP-BAIDU && H5 -->`  
hover-stop-propagation='hoverStopPropagation'
`    <!--  #endif -->`
`>`
view 组件
`</view>`
`</template>`
格式化后
`<template>`
`<view :hover-class="hoverClass" :hover-start-time='hoverStartTime' :hover-stay-time='hoverStayTime' <!-- #ifndef`
    `APP-NVUE && MP-ALIPAY && MP-BAIDU && H5 -->`  
hover-stop-propagation='hoverStopPropagation'
`    <!--  #endif -->`
`>`
view 组件
`</view>`
`</template>`
格式化后编译不成功。
不会让我把条件编译放外面来解决问题吧?

操作步骤:
见上

预期结果:
见上

实际结果:
见上

bug描述:

更多关于uni-app HB格式化会破坏HTML的格式的实战教程也可以访问 https://www.itying.com/category-93-b0.html

4 回复

格式化前
<template>
<view :hover-class=“hoverClass” :hover-start-time=‘hoverStartTime’ :hover-stay-time=‘hoverStayTime’

hover-stop-propagation=‘hoverStopPropagation’ > view 组件 </view> </template> 格式化后 <template> <view :hover-class=“hoverClass” :hover-start-time=‘hoverStartTime’ :hover-stay-time=‘hoverStayTime’
hover-stop-propagation=‘hoverStopPropagation’ > view 组件 </view> </template>

更多关于uni-app HB格式化会破坏HTML的格式的实战教程也可以访问 https://www.itying.com/category-93-b0.html


你这里会编译html 我直接放图


前图是格式化后的。后图是格式化前的情况。格式化后导致编译不成功

这是一个已知的HBuilderX格式化功能在处理条件编译注释时的缺陷。当条件编译注释(如 <!-- #ifndef -->)与Vue模板属性位于同一行时,格式化工具会错误地将其识别为普通HTML注释并进行换行,导致语法破坏。

根本原因:格式化引擎未能正确解析Vue单文件组件中条件编译注释的特殊语法,将其与常规HTML/XML注释混淆。

临时解决方案(推荐)

  1. 将条件编译注释单独成行:这是目前最可靠的写法。确保 <!-- #ifndef --><!-- #endif --> 各自独占一行,不与属性放在同一行。
    <view 
      :hover-class="hoverClass" 
      :hover-start-time='hoverStartTime' 
      :hover-stay-time='hoverStayTime'
      <!-- #ifndef APP-NVUE && MP-ALIPAY && MP-BAIDU && H5 -->
      hover-stop-propagation='hoverStopPropagation'
      <!-- #endif -->
    >
回到顶部