2***@qq.com
2***@qq.com
  • 发布:2024-09-05 00:02
  • 更新:2024-09-05 10:25
  • 阅读:70

v-for循环两段相同的代码,一个项目正常运行,一个项目报错Unresolved reference:

分类:uni-app x

我创建了两个项目,旧的项目中真机运行就会报错Unresolved reference: xxx
旧项目web端可以正常运行,新项目中也可以正常运行
这是uvue:

    <template>  
    <view>  
        <view v-for="(item,index) in objectArray" :key="item.id">  
            {{index+":"+item.name}}  
        </view>  
        </view>  
    </template>  
    <script>  
    export default {  
        data () {  
            return {  
                objectArray: [{  
                    id: 0,  
                    name: '李强',  
                    age:"16",  
                    long:"160"  
                },{  
                    id: 1,  
                    name:'张三',  
                    age:"17",  
                    long:"170"  
                },{  
                    id:2,  
                    name:"jack",  
                    age:"18",  
                    long:"180"  
                }],  

            }  
        }  
        }  
</script>  

<style>  

</style>

旧项目真机运行报错

error: Unresolved reference: id‌  
23:44:11.569 at pages/index/home/home.uvue:3:55  
23:44:11.569 1  |   <template>  
23:44:11.569 2  |   <view>  
23:44:11.569 3  |    <view v-for="(item,index) in objectArray" :key="item.id">  
23:44:11.569    |                                                         ^  
23:44:11.569 4  |     {{index+":"+item.name}}  
23:44:11.569 5  |    </view>  
23:44:11.570 ‌error: Unresolved reference: name‌  
23:44:11.570 at pages/index/home/home.uvue:4:20  
23:44:11.570 2  |   <view>  
23:44:11.570 3  |    <view v-for="(item,index) in objectArray" :key="item.id">  
23:44:11.570 4  |     {{index+":"+item.name}}  
23:44:11.570    |                      ^  
23:44:11.570 5  |    </view>  
23:44:11.570 6  |    </view>
2024-09-05 00:02 负责人:无 分享
已邀请:
爱豆豆

爱豆豆 - 办法总比困难多

加上类型 试试

    <template>    
    <view>    
        <view v-for="(item,index) in objectArray" :key="item.id">    
            {{index+":"+item.name}}    
        </view>    
        </view>    
    </template>    
    <script>    
    type ListItem = {  
      id : number,  
      name : string,  
      age : string,  
      long : string,  
    }  
    export default {    
        data () {    
            return {    
                objectArray: [{    
                    id: 0,    
                    name: '李强',    
                    age:"16",    
                    long:"160"    
                },{    
                    id: 1,    
                    name:'张三',    
                    age:"17",    
                    long:"170"    
                },{    
                    id:2,    
                    name:"jack",    
                    age:"18",    
                    long:"180"    
                }] as ListItem[],    

            }    
        }    
        }    
</script>    

<style>    

</style>
DCloud_UNI_yuhe

DCloud_UNI_yuhe

你尝试一个给objectArray指定type。

要回复问题请先登录注册