GV000
GV000
  • 发布:2023-12-05 16:50
  • 更新:2023-12-05 17:06
  • 阅读:322

模板嵌套 v-for 报错

分类:uni-app x
<template>  
  <view v-for="item in dataList" :key="item['id']">  
    <view>{{item['username']}}</view>  
    <view v-for="(t,index) in item['tag']" :key="index">  
      <view>{{t}}</view>  
    </view>  
  </view>  
</template>
export default {  
  data(){  
    return {  
      dataList: [id: 1, username:"test", tag: ["1","2"]  
    }  
  }  
}

代码如上

报错代码行如下

<view v-for="(t,index) in item['tag']" :key="index">

报错信息如下
error: Cannot infer a type for this parameter. Please specify it explicitly.‌

编译错误如下
16:42:55.907 [plugin:uni:app-uts] 编译失败
16:42:55.907 ‌error: None of the following functions can be called with the arguments supplied: ‌
16:42:55.907 ‌public final fun <T : UTSObject> renderList(source: TypeVariable(T)?, renderItem: (value: Any?, key: String, index: Number?) -> VNode): UTSArray<VNode> defined in io.dcloud.uniapp.vue.RenderHelpers.Companion‌
16:42:55.908 ‌public final fun <T> renderList(source: UTSArray<TypeVariable(T)>?, renderItem: (value: TypeVariable(T), key: Number, index: Number?) -> VNode): UTSArray<VNode> defined in io.dcloud.uniapp.vue.RenderHelpers.Companion‌
16:42:55.908 ‌public final fun renderList(source: Number?, renderItem: (value: Number, key: Number, index: Number?) -> VNode): UTSArray<VNode> defined in io.dcloud.uniapp.vue.RenderHelpers.Companion‌
16:42:55.908 ‌public final fun renderList(source: String?, renderItem: (value: String, key: Number, index: Number?) -> VNode): UTSArray<VNode> defined in io.dcloud.uniapp.vue.RenderHelpers.Companion‌

2023-12-05 16:50 负责人:无 分享
已邀请:

最佳回复

爱豆豆

爱豆豆 - 办法总比困难多

可以加上类型试试
具体请参考uts:https://uniapp.dcloud.net.cn/uni-app-x/uts/data-type.html

<template>    
  <view v-for="item in dataList" >    
    <view>{{item.username}}</view>    
    <view v-for="(t,index) in  item.tag" :key="index">    
      <view>{{t}}</view>    
    </view>   
  </view>    
</template>  

<script lang="uts">  
    type dataListItem = {  
      id : number,  
      tag : Array<string>,  
      username : string,  
    }  
    export default {  
        data() {  
            return {  
                dataList: [{id: 1, username:"test", tag: ["1","2"] },{id: 2, username:"test2", tag: ["3","2"] }] as dataListItem[]  
            }  
        },  
        methods: {  

        }  
    }  
</script>  

<style>  

</style>  
  • GV000 (作者)

    已解决,谢谢

    2023-12-05 17:10

GV000

GV000 (作者) - 全栈开发工程师

想知道怎么推断这个类型去解决

要回复问题请先登录注册