html - 使用 JSON 值作为带有 vue 的 HTML 标记
问题描述
我有一个输出以下样式的 JSON 文件:
{
"h1" : {
"font-family" : "Lato",
"font-size" : "24px",
"line-height" : "28px",
"font-weight" : 600,
"colorId" : 3,
"margin-bottom" : "10px",
"margin-top" : "20px"
},
"h2" : {
"font-family" : "Lato",
"font-size" : "20px",
"line-height" : "24px",
"font-weight" : 600,
"colorId" : 3,
"margin-bottom" : "10px",
"margin-top" : "20px"
}
}
我想使用第一个键“h1,h2,...”作为 HTML 标记来显示它。Vue可以做到这一点吗?
它应该是这样的:
<div v-for="(props, tag) in headers">
<{{ tag }}>x</ {{ tag }}>
</div>
解决方案
<div v-for="(props, tag) in headers" v-html="`<${tag}>x</${tag}>`"></div>
推荐阅读
- python - url open 在某些网站而不是其他网站上返回错误
- segmentation-fault - !$OMP PARALLEL 在 fortran 和分段错误中的问题
- pandas - 通过 putty 在本地服务器上安装 numpy 的问题
- python - 如何在python中验证isdigit()中的浮点数
- regex - 向已创建的正则表达式添加条件
- android - 无法使用 kotlin 在 google 登录上为 android 选择不同的帐户
- html - 悬停在导航上的效果。li 但排除其余的 li 元素
- r - 精度函数的 ACF1 结果为空
- python - 如何使用循环将列表的元素输入到字符串中?
- c - 当没有给出明确的值时,是什么决定了 C 数组中项目的初始值?