4***@qq.com
4***@qq.com
  • 发布:2022-06-27 02:22
  • 更新:2022-06-27 08:23
  • 阅读:179

如何处理拼接数组

分类:uni-app
data() {  
            return {  
                news: [],  
                categories: [],  
                all_categories : [{  
                    id : '',  
                    name : '全部'  
                }],  
                skeleton : true,  
            }  
        },

categories里的数据是接口返回的,如下:

0 : {…}  
1 : {…}  
2 : {…}  

我现在想要用nushift把all_categories加到categories开头

this.categories.unshift(this.all_categories);

但是加出来以后成了

0 : {…}  
  0 : {…} //加入的数据  
1 : {…}  
2 : {…}  
3 : {…}

多了一组嵌套,不对了,我要怎么处理才能不多这一组嵌套把新数组加进去呢???

2022-06-27 02:22 负责人:无 分享
已邀请:
8***@163.com

8***@163.com

this.categories.unshift(this.all_categories[0]);
或this.all_categories.concat(this.categories);

要回复问题请先登录注册