vue.js - 在 vue.js 的 UL 中渲染 LI。有隐形标签吗?
问题描述
如何在 vue 中从 v-for 中渲染 li。
我想做这样的事情。
<ul class="list-unstyled">
<span v-for="(item, name) in lineItem.properties" v-html="item"></span>
</ul>
但我显然不希望跨度被渲染,因为 item 很可能会带回多个 li。在我的例子中,item 会返回已经渲染成一个 li 的 li 内容。
非常感谢。
解决方案
你需要使用这个https://github.com/Thunberg087/vue-fragment#readme
<ul class="list-unstyled">
<fragment v-for="(item, name) in lineItem.properties" v-html="item"></fragment>
</ul>
ps 如果您使用的是 vue 3,您甚至不需要安装库,它是开箱即用的! https://v3.vuejs.org/guide/migration/fragments.html
推荐阅读
- google-apps-script - 使用 DuplicateObject 请求的变量键创建 objectIds 映射
- c# - 源不包含 DataRows。在 for 循环中进行一次迭代时出错
- sql - SQL Server Case 语句部分工作
- postgresql - Postgresql 酸合规性
- javascript - 如何从数组中获取唯一值,另一个角度?
- java - 如何在 Symja 中修复精度?
- bash - Bash - Echo 正在拆分我的字符串结果
- amazon-web-services - 在 AWS 上安装 SSL
- python - 将float转换为str时如何检查默认小数精度?
- django - django-allauth :删除注册表单中的密码字段