javascript - 在 Vue 模板中显示一个对象
问题描述
我有一个像这样的对象:
Obj = {
'min_mix': 1,
'max_mix': 2,
'climbing': {
'easy':[
{
'hour': 1.0,
'id':0,
}
],
'height': [
{
'hour': 1.0,
'price': 100
}
]
}
}
我必须在我的 HTML 中显示这个:
min_mix : 1
max_mix : 2
climbing:
easy:
hour : 1.0
id : 0
height:
hour: 1.0
price: 100
现在我使用了一些 v-for,但我没有一个好的结果,我不明白如何正确显示数组的简单和高度?
解决方案
请检查此 https://jsfiddle.net/Lewvsp0k/
<v-card-text v-for='(value,name) in obj' :key='name' class="pt-0 pb-0">
<template v-if="typeof value !== 'object'">
<b>{{name}} : {{ value }} </b>
</template>
<template v-else>
<div v-for="(rowValue, rowIndex) in value" :key='rowIndex' class="mb-2 pa-0">
<b>{{name}} : </b>
<div v-for="(rowValue1, rowIndex1) in rowValue" :key='rowIndex1' class="mb-2 pa-0">
<b>{{rowIndex1}} : </b>
<div>
<div v-for="rowValue2 in rowValue1" :key='rowValue2' class="mb-2 pa-0">
<div v-for="(rowValue3, rowIndex3) in rowValue2" :key='rowValue3' class="mb-2 pa-0">
<b> {{rowIndex3}} : {{rowValue3}} </b>
</div>
</div>
</div>
</div>
</div>
</template>
</v-card-text>
推荐阅读
- sql - 使用解析函数查询同类产品
- javascript - 当所选行是最后一行但表在 div 内时自动滚动表
- haskell - 在 Haskell 中使用非分数复数
- c++ - winsock2 不支持原始套接字侦听
- reactjs - 在 React Hook 中获取默认值?
- git - 如何用 shell 显示 git 忽略的文件?
- python - python中的网络抓取返回“无”
- flutter - Flutter:如何处理 Flutter 与 API + MongoDB 的命名约定不同以及名称不匹配的问题?
- angular - mat-error 没有出现在 ControlValueAccessor 中
- azure - 降低流分析集群的成本