uniapp删除线
在 uniapp 中实现删除线效果可以通过以下几种方式:
使用 CSS text-decoration 属性
通过 CSS 的 text-decoration 属性可以轻松实现删除线效果。在样式中添加以下代码:
.text-strikethrough {
text-decoration: line-through;
}
在模板中使用:
<view class="text-strikethrough">这段文字将有删除线</view>
使用内联样式
如果希望直接在元素上应用样式,可以使用内联样式:
<view style="text-decoration: line-through;">这段文字将有删除线</view>
使用条件渲染
当需要根据条件动态显示删除线时,可以结合条件判断:
<view :style="{textDecoration: isDeleted ? 'line-through' : 'none'}">动态删除线</view>
使用 rich-text 组件
对于需要更复杂文本样式的情况,可以使用 rich-text 组件:
<rich-text :nodes="'<del>这段文字有删除线</del>'"></rich-text>
注意事项
- 删除线颜色默认与文字颜色相同,可以通过
text-decoration-color修改 - 在某些平台(如小程序)上可能需要检查样式兼容性
- 对于多行文本,删除线会贯穿每一行







