j52997 2022-06-25 14:48 采纳率: 100%
浏览 18
已结题

数组图片无法正常遍历

数组内图片无法正常遍历

从本地获取数据,在onLoad的时候push到数组里并且循环

<view v-for="(item,index) in heroSj" :key="index">
            <view class="uni-row box">
                <view>
                    <image class="img1" :src='item.url'></image>
                </view>
                <view class="text">{{ item.name1 }}</view>
                <view class="text">{{ item.name2 }}</view>    
            </view>
            <view class="uni-row box">
                <view>
                    <image class="img2" :src="item.url2" mode=""></image>
                    <!-- <barckground-img class="img2" :url='item.url2'></barckground-img> -->
                </view>
            </view>
        </view>

onLoad:function() {
            that = this;
            // 同步取缓存
            // const res = uni.getStorageSync('id');
            //     if (res){
            //             var sj = [];
            //             sj = JSON.parse(JSON.stringify(res));
            //             console.log(sj);
            //             that.heroSj.push(sj);
            //             console.log('载入');
            //         }            
            
            // 异步取缓存
            uni.getStorage({
                    key:'id',
                    success: function (res) {
                        var sj = [];
                        sj = JSON.parse(JSON.stringify(res.data));
                        console.log(sj);
                        that.heroSj.push(sj);
                        console.log('载入');
                    }
                });
            },

如图使用image的话会报错渲染问题

img

换成barckground-img虽然不会再出现渲染报错,但是url2数组里面的图片无法渲染到页面上,并且没有任何报错。

img

把url2和url的渲染位置互换渲染失败,报错渲染问题

  • 写回答

1条回答 默认 最新

  • j52997 2022-06-25 17:51
    关注

    在大佬的指点下解决了问题

    <view v-for="(itemson,index2) in item.url2" :key='index2'>
                        <image class="img2" :src="itemson" mode=""></image>
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 7月3日
  • 已采纳回答 6月25日
  • 创建了问题 6月25日