1***@163.com
1***@163.com
  • 发布:2022-10-15 14:19
  • 更新:2022-10-17 12:04
  • 阅读:239

uniapp使用云对象返回结果赋值后云对象的值被改变了,导致数据无法正确赋值

分类:uniCloud

建立了一个云对象文件,该对象中只有一个简单方法返回数据

module.exports = {  
    _before: function() { // 通用预处理器  
    },  
    async getCategory() {  
        // const db = uniCloud.database();  
        // let list = await db.collection('category').where({  
        //  enable: true,  
        //  pid: '0'  
        // }).get();  
        return [{id:"11",name:"sss"}];  
    }  
}

页面调用:

    async getCategory(){  
                let that=this;  
                try{  
                let proObj=uniCloud.importObject("product")  
                 let obj=   await proObj.getCategory();  
                    console.log("resresresres",obj);   
                    const arr=obj;  
                    console.log("arr",arr);  
                    this.list=arr  
                    console.log("this.list",this.list);  
                }  
                catch(e){  
                    //TODO handle the exception  
                    console.log("发生错误");  
                }  
            },

然后在页面中调用云对象的该方法,拿到数据赋值,赋值后返回的数据被改变了,打印如下

  • 当我不使用this.xxx=obj赋值时,正确打印数据
14:19:09.322 resresresres [{"id":"11","name":"sss"}]  at pages/diancan/diancan.vue:143  
14:19:09.332 arr [{"id":"11","name":"sss"}]  at pages/diancan/diancan.vue:145  
  • 当我使用this.xxx=obj赋值时,值被改变了

    14:20:23.426 resresresres [{"__ob__":{"dep":{"id":111623,"subs":[]},"value":{"__ob__":{"dep":{"id":111623,"subs":[]},"value":{"__ob__":{"dep":"Object","value":"Object","vmCount":0}},"vmCount":0}},"vmCount":0}}]  at pages/diancan/diancan.vue:143  
    14:20:23.434 arr [{"__ob__":{"dep":{"id":111623,"subs":[]},"value":{"__ob__":{"dep":{"id":111623,"subs":[]},"value":{"__ob__":{"dep":"Object","value":"Object","vmCount":0}},"vmCount":0}},"vmCount":0}}]  at pages/diancan/diancan.vue:145  
    14:20:23.440 this.list [{"__ob__":{"dep":{"id":111623,"subs":[]},"value":{"__ob__":{"dep":{"id":111623,"subs":[]},"value":{"__ob__":{"dep":"Object","value":"Object","vmCount":0}},"vmCount":0}},"vmCount":0}}]  at pages/diancan/diancan.vue:147  
    

环境:

hbuilderx :3.6.4

2022-10-15 14:19 负责人:无 分享
已邀请:
DCloud_uniCloud_WYQ

DCloud_uniCloud_WYQ

这个是vue添加的,不影响你正常访问里面的数据

该问题目前已经被锁定, 无法添加新回复