5***@qq.com
5***@qq.com
  • 发布:2022-10-04 12:23
  • 更新:2022-10-04 12:23
  • 阅读:395

unicloud云数据库,获取json格式时输出为:"__ob__": {"dep": {...

分类:uniCloud

问题

使用云函数获取云数据库的数据时,发现json对象没有赋值前打印出来是正常的,但是赋值之后打印出来就变成了如下:

{  
    "affectedDocs": 2,  
    "data": [{  
        "__ob__": {  
            "dep": {  
                "id": 672,  
                "subs": [{  
                    "active": true,  
                    "before": "function before () {\n      if (vm._isMounted && !vm._isDestroyed) {\n        callHook(vm, 'beforeUpdate');\n      }\n    }",  
                    "cb": "function noop (a, b, c) {}",  
                    "deep": false,  
                    "depIds": "Object",  
                    "deps": "Object",  
                    "dirty": false,  
                    "expression": "function () {\n      vm._update(vm._render(), hydrating);\n    }",  
                    "getter": "function () {\n      vm._update(vm._render(), hydrating);\n    }",  
                    "id": 121,  
                    "lazy": false,  
                    "newDepIds": "Object",  
                    "newDeps": "Object",  
                    "sync": false,  
                    "user": false,  
                    "vm": "Object"  
                }]  
            },  
            "value": {  
                "__ob__": {  
                    "dep": {  
                        "id": 672,  
                        "subs": "Object"  
                    },  
                    "value": {  
                        "__ob__": "Object"  
                    },  
                    "vmCount": 0  
                }  
            },  
            "vmCount": 0  
        }  
    }, {  
        "__ob__": {  
            "dep": {  
                "id": 686,  
                "subs": [{  
                    "active": true,  
                    "before": "function before () {\n      if (vm._isMounted && !vm._isDestroyed) {\n        callHook(vm, 'beforeUpdate');\n      }\n    }",  
                    "cb": "function noop (a, b, c) {}",  
                    "deep": false,  
                    "depIds": "Object",  
                    "deps": "Object",  
                    "dirty": false,  
                    "expression": "function () {\n      vm._update(vm._render(), hydrating);\n    }",  
                    "getter": "function () {\n      vm._update(vm._render(), hydrating);\n    }",  
                    "id": 121,  
                    "lazy": false,  
                    "newDepIds": "Object",  
                    "newDeps": "Object",  
                    "sync": false,  
                    "user": false,  
                    "vm": "Object"  
                }]  
            },  
            "value": {  
                "__ob__": {  
                    "dep": {  
                        "id": 686,  
                        "subs": "Object"  
                    },  
                    "value": {  
                        "__ob__": "Object"  
                    },  
                    "vmCount": 0  
                }  
            },  
            "vmCount": 0  
        }  
    }]

解决办法

事实上这个是vue的ob: Observer这些数据是vue这个框架对数据设置的监控器。不能够直接打印但是也是可以获取数据的

const va = uniCloud.importObject("getques")  
const ans = await va.getList()  
this.res = ans.data//给本地的res对象赋值  
console.log(ans)//这样打印出来就是如上代码一样是看不到数据的
console.log(this.res.data[0].que)//这样打印就可以打印出正常的数据了打印结果是

image-20221004122027580

其实可以正常操作了,在v-for中遍历

image-20221004122110420

得到结果

image-20221004121912567

参考文章

Vue ob: Observer 对象

0 关注 分享

要回复文章请先登录注册