3***@qq.com
3***@qq.com
  • 发布:2020-11-13 11:46
  • 更新:2023-02-09 18:16
  • 阅读:16171

【报Bug】TypeError: Invalid attempt to destructure non-iterable instance.

分类:uni-app

产品分类: uniapp/App

PC开发环境操作系统: Windows

PC开发环境操作系统版本号: win10

HBuilderX类型: 正式

HBuilderX版本号: 2.9.8

手机系统: Android

手机系统版本号: Android 10

手机厂商: 小米

手机机型: K30

页面类型: vue

打包方式: 云端

项目创建方式: HBuilderX

操作步骤:

安卓真机调试

预期结果:

解决问题

实际结果:

无解

bug描述:

一个简单的测试页面,H5正常,上app就提示

11:37:48.725 cid unmatched [object Object] at view.umd.min.js:1  
11:37:48.755 TypeError: Invalid attempt to destructure non-iterable instance.  
11:37:48.787 In order to be iterable, non-array objects must have a [Symbol.iterator]() method. at view.umd.min.js:1  
11:37:48.819 cid unmatched [object Object] at view.umd.min.js:1  
11:37:48.848 TypeError: Invalid attempt to destructure non-iterable instance.  
11:37:48.879 In order to be iterable, non-array objects must have a [Symbol.iterator]() method. at view.umd.min.js:1  
11:37:48.910 cid unmatched [object Object] at view.umd.min.js:1  
11:37:48.941 TypeError: Invalid attempt to destructure non-iterable instance.  
11:37:48.972 In order to be iterable, non-array objects must have a [Symbol.iterator]() method. at view.umd.min.js:1  
11:37:49.005 cid unmatched [object Object] at view.umd.min.js:1  
11:37:49.036 TypeError: Invalid attempt to destructure non-iterable instance.  
11:37:49.068 In order to be iterable, non-array objects must have a [Symbol.iterator]() method. at view.umd.min.js:1  
11:37:49.098 cid unmatched [object Object] at view.umd.min.js:1  
11:37:49.129 TypeError: Invalid attempt to destructure non-iterable instance.  
11:37:49.159 In order to be iterable, non-array objects must have a [Symbol.iterator]() method. at view.umd.min.js:1  
11:37:49.190 cid unmatched [object Object] at view.umd.min.js:1  
11:37:49.222 TypeError: Invalid attempt to destructure non-iterable instance.  
11:37:49.253 In order to be iterable, non-array objects must have a [Symbol.iterator]() method. at view.umd.min.js:1  
11:37:49.284 cid unmatched [object Object] at view.umd.min.js:1  
11:37:49.315 TypeError: Invalid attempt to destructure non-iterable instance.  
11:37:49.346 In order to be iterable, non-array objects must have a [Symbol.iterator]() method. at view.umd.min.js:1  
11:37:49.377 cid unmatched [object Object] at view.umd.min.js:1  
11:37:49.408 TypeError: Invalid attempt to destructure non-iterable instance.  
11:37:49.439 In order to be iterable, non-array objects must have a [Symbol.iterator]() method. at view.umd.min.js:1  
11:37:49.470 cid unmatched [object Object] at view.umd.min.js:1  
11:37:49.502 TypeError: Invalid attempt to destructure non-iterable instance.  
11:37:49.533 In order to be iterable, non-array objects must have a [Symbol.iterator]() method. at view.umd.min.js:1  
11:37:49.563 Not found -1;-1,4,5-0;undefined at view.umd.min.js:1  
11:37:49.595 Error: Not Found:Page[1][-1;-1;-1,4,5-0;undefined,6-0] at view.umd.min.js:1

代码如下

<template>  
    <view class="container">  
        <view style="text-align: center; text-autospace: inherit; ">  
            <button type="primary" @click="getBalls()" size="mini">点我一下</button>  
            <button type="warn" @click="clearBalls()" size="mini">重置一下</button>  
        </view>  

        <uni-list  style="display: flex;">  
            <uni-list-item v-for="(item, index) in ballsArr" :key="item.index"    :showArrow="false">  
                <uni-grid :column="7"  >  
                    <uni-grid-item   v-for="(ball, i) in item" :key="i" style="display: flex;">  
                        <text :style="{ color: ball.color }">{{ ball.name + '   ' }}</text>  
                    </uni-grid-item>  
                </uni-grid>  
            </uni-list-item>  
        </uni-list>  
    </view>  
</template>  

<script>  
export default {  
    data() {  
        return {  
            ballsArr: new Array(0)  
        };  
    },  
    methods: {  
        getBalls() {  
            var balls = [];  
            var redRes = [];  
            var redBalls = initArr(33);  
            for (let index = 0; index < 6; index++) {  
                redBalls = randomArr(redBalls);  
                redRes.push(redBalls.pop());  
            }  
            redRes = redRes.sort(function(a, b) {  
                return a - b;  
            });  
            var i = 1;  
            redRes.forEach(x => {  
                balls.push({ name: x, color: 'red', index: i });  
                i++;  
            });  
            var blue = randomArr(initArr(16)).pop();  
            balls.push({ name: blue, color: 'blue', index: i });  

            this.ballsArr.push(balls);  

        },  
        clearBalls() {  
            this.ballsArr = [];  
        }  
    },  
};  

var randomArr = (arr = []) => {  
    let i = arr.length;  
    while (i) {  
        let j = Math.floor(Math.random() ** 0.5 * i--);  
        [arr[i], arr[j]] = [arr[j], arr[i]];  
    }  
    return arr;  
};  

var initArr = n => {  
    var temp = [];  
    for (let index = 1; index <= n; index++) {  
        temp.push(index);  
    }  
    return temp;  
};  

</script>  

<style>  
.container {  
    padding: 20px;  
    font-size: 14px;  
    line-height: 24px;  
}  
</style>  
2020-11-13 11:46 负责人:无 分享
已邀请:
3***@qq.com

3***@qq.com (作者) - goodve

解决了...

   <uni-list-item v-for="(item, index) in ballsArr" :key="item.index"    :showArrow="false">  

改成

   <uni-list-item v-for="(item, index) in ballsArr" :key="index"    :showArrow="false">  

就好了

2***@qq.com

2***@qq.com

那为何我的key没错,还是这个错误呢,求解

3***@qq.com

3***@qq.com

我也是:key写错了,找了半天,最后你给了灵感

6***@qq.com

6***@qq.com - kkimchi

6666666666666666666666,谢谢,气死我了,一个key,找了半天

s***@lln.kim

s***@lln.kim

我的key没错也报这个,实在找不到原因,先这样不影响使用

z***@timesgroup.cn

z***@timesgroup.cn

感谢大佬提醒 我也遇到了~~

2***@qq.com

2***@qq.com

同求,全局查了所有文件的key都没有错,但是也是报了一大堆这个错,无语。

2***@qq.com

2***@qq.com

我是扩展组件card渲染不出来才报的这个错,是有时候渲染不出来,我搞不懂什么情况

牯牛

牯牛

我的也是key的问题;
key用了data._id的形式,因为data下的_id属性为空,在真机上报了这个错误;
在浏览器上没有报错;
后面直接给data._id赋值就好了

要回复问题请先登录注册