2***@qq.com
2***@qq.com
  • 发布:2025-01-03 11:15
  • 更新:2025-01-03 12:12
  • 阅读:94

小白很郁闷,v-for一直报错error: Unresolved reference: text‌

分类:uni-app x

本人小白第一次用uniapp X的uts语法写一个列表,上来就掉坑爬不出来了,求大佬帮我看下


<template>  
    <scroll-view class="app-bg">  
        <view class="uni-margin-wrap">  
            <!--    <swiper id="swiper-view" class="swiper">  
                <swiper-item v-for="(item, index) in bannerList" :key="item.id">  
                    <view class="swiper-item uni-bg-red">  
                        <image class="banner-image" :src="item.url"></image>  
                    </view>  
                </swiper-item>  

            </swiper> -->  
            <text v-for="(item , index) in list" :key="item.id">{{item.text}}</text>  
        </view>  

    </scroll-view>  

</template>  

<script setup>  
    const list = ref([  
        {  

            id: 1,  
            text: 'A'  
        },  
        {  

            id: 2,  
            text: 'B'  
        },  
        {  

            id: 3,  
            text: 'C'  
        }  
    ]);  
</script>

运行安卓基座,用模拟器跑,HbuilderX一直报错:error: Unresolved reference: text‌, Hbuilder版本是4.36,这是为什么?

2025-01-03 11:15 负责人:无 分享
已邀请:
套马杆的套子

套马杆的套子 - 没有解决不了的问题,只有解决不完的问题

这么写试试呢,我也是刚开始研究

interface ListItem {  
    id: number;  
    text: string;  
}  

const list = ref<ListItem[]>([  
    {  
        id: 1,  
        text: 'A'  
    },  
    {  
        id: 2,  
        text: 'B'  
    },  
    {  
        id: 3,  
        text: 'C'  
    }  
]);
毛毛不是泰迪

毛毛不是泰迪

参考这个帖子的回复试试:https://ask.dcloud.net.cn/question/185726

  • 2***@qq.com (作者)

    感谢您的回复,问题已解决,必须声明类型,或者用UTSJSONObject类型

    2025-01-05 13:32

要回复问题请先登录注册