灯下等雪
灯下等雪
  • 发布:2024-06-06 08:38
  • 更新:2024-06-06 08:47
  • 阅读:72

v-for是不是不支持二层及以上的嵌套

分类:uni-app x

我定义了一个镇和村的数据结构

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 08:38 负责人:无 分享
已邀请:
沈工

沈工

<view class="cun-item" v-for="(cun, index) in zhen" :key="index"> 这句改 <view class="cun-item" v-for="(cun, index) in zhen.cun" :key="index">应该可以帮你实现了

  • 灯下等雪 (作者)

    尴尬。犯了个低级错误

    2024-06-06 09:12

要回复问题请先登录注册