前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布

bug?

作者头像
xiny120
发布2021-04-30 14:52:08
6360
发布2021-04-30 14:52:08
举报
文章被收录于专栏:毛毛v5
代码语言:javascript
复制
        onLoad(e){
            setTimeout(() => {
                let that = this;
                uniCloud.callFunction({name: 'api',data: {action:e.ac,},
                    success: (e) => {
                        if (e.result.code == 0) {
                            var n = 1;
                            if(n === 0){
                                //this.detail = e.result.data.data['0']; // 这里用this不行。
                                console.log(e.result.data.data['0']);
                                //console.log(this.detail);
                            }else if(n === 1){
                                //that.detail = e.result.data.data['0']; // 这里用that也不行。
                                console.log(e.result.data.data['0']);                       
                            }else if(n === 2){
                                setTimeout(function(){
                                    this.detail = e.result.data.data['0']; //只有这里是对的
                                    console.log(this.detail);
                                },1);
                            }else{
                                setTimeout(function(){
                                    console.log(e.result.data.data['0']);
                                    that.detail = e.result.data.data['0'];//setTimeout里面用that也不对
                                },1);                           
                            }
                        } else {
                            uni.showModal({
                                content: e.result.message,
                                showCancel: false
                            })
                        }
                    },
                    fail: (e) => {
                        uni.showModal({
                            content: JSON.stringify(e),
                            showCancel: false
                        })
                    },
                    complete: () => {
                    }
                })              
            }, 0)    //箭头函数中的this总是指向外层调用者,也就是Obj           
        },
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档