我定义了一个镇和村的数据结构
type Cun = {
name : string
today : string
month : string
}
type Zhen = {
name : string
water : string
cun : Cun[]
}
const list = ref<Zhen[]>([
{
"name": "横林镇",
"water": "5.2",
"cun": [
{
"name": "吴家村",
"today": "1.0",
"month": "100",
},
{
"name": "李家村",
"today": "2.0",
"month": "200",
},
]
}
])
template标签部分
<view class="city-item" v-for="zhen in list" :key="zhen.name">
<view class="zhen-item">
<text style="font-weight: bold;font-size:24rpx;color:#333">{{zhen.name}}</text>
</view>
<view class="cun-item" v-for="(cun, index) in zhen" :key="index">
// 报错error: Unresolved reference: name
<view class="item-name">{{cun.name}}</view>
// 不报错,安卓模拟器可以展示cun的内容
<view class="item-name">{{cun}}</view>
</view>
</view>
灯下等雪 (作者)
尴尬。犯了个低级错误
2024-06-06 09:12