Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
255 views
in Technique[技术] by (71.8m points)

Promise的意义是什么?

在做微信小程序的时候遇到了请求异步的问题,导致代码冗长而且复用性很低。后来研究了promise但是发现这个东西并不能解决以上问题

之前的小程序代码类似于这样

wx.request{{
    url:'xxx',
    data:{
        data:somthing
    },
    success:function(){
         wx.request{{
            url:'xxx',
            data:{
                data:somthing
            },
            success:function(){
                
            }
}}
    }
}}

然后 promise 代码类似于这样 
    wx.pro.request({
        url:'xxx',
        data:{
            data:somthing
        },
    }).then(function(data){
         wx.pro.request({
            url:'xxx',
            data:{
                data:somthing
            },
        }).then(function(data){
            
        });
    });

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

我说怎么这么别扭 你的.then写错地方了
应该是这样的结构a().then(b).then(c)
你写的是a().then(b.then(c))


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...