非常奇怪的page页数据问题?

小程序 文章 2021-03-11 10:41 398 0 全屏看文

AI助手支持GPT4.0

非常奇怪的page页数据问题?Very strange page data problem?

非常奇怪的page页数据问题?

首先我在onload函数中获取openid并setdata到页面data中,此时打印data,存在openid

wx.cloud.callFunction({            name:'getOpenidtest',            success:res =>{                console.log(res,'11111111111');                //console.log(res.result.openid);                this.setData({                    openid:res.result.openid                })                console.log(this.data);            },            fail:res =>{                console.log(res,'11111111111');            }        })

然后在onshow里调用openapi,他却消失了,打印data,openapi存在

 onShow:function(){        const { goods_id,countDownTxt} = this.data;        const openid = this.data.openid                if(countDownTxt == null){            wx.cloud.callFunction({                name:'sendMessagetest',                data:{                     goods_id,                     openid                                     },                success:res =>{                    console.log(this.data);                    console.log(res,'sendMessage正在被执行',openid,goods_id);                },                fail:res =>{                    console.log(res,'fail');                }            })        }        //获取openid            }

大致就是这种情况,求解答

First of all, I get the openid in the onload function and set the data to the page data. At this time, I print the data and the openid exists wx.cloud.callFunction ({            name:'getOpenidtest',             success:res  =>{                 console.log (res,'11111111111');                // console.log ( res.result.openid );                  this.setData ({                     openid:res.result.openid                 })                 console.log ( this.data );            },             fail:res  =>{                 console.log (res,'11111111111'); Then call OpenAPI in Onshow, but it disappears. Print data, OpenAPI exists onShow:function (){        const { goods_ id,countDownTxt} =  this.data ;        const openid =  this.data.openid                 if(countDownTxt == null){             wx.cloud.callFunction ({                name:'sendMessagetest',                data:{                     goods_ id,                     openid                                     },                 success:res  =>{                     console.log ( this.data );                     console.log (RES, 'SendMessage is being executed', openid, goods_ id);                },                 fail:res  =>{                     console.log (RES, 'fail');})} / / getting openid} is roughly the case. Please find the solution

回答:

陈宇明:
console.log(res,'sendMessage正在被执行',this.data.openid,goods_id);你这样输出试试


跨商通:

谢邀。

应该是异步问题。

onShow里的代码并不一定比onLoad里的代码更晚执行。

Mr.Zhao:

打印的时候用 console.log(JSON.stringify(this.data)) 你再观察下,会有不一样的结果

Wdam:没能观察出来解决办法,还是一个有一个无
Wdam:
Wdam:确实不太理解,我看到打印出来的数据格式变了
Mr.Zhao:把这个打印结果研究明白了,你就解决了

-EOF-

AI助手支持GPT4.0