GithubHelp home page GithubHelp logo

putData 在异步请求的回调里,如果请求回调比onload调用慢,onload里就取不到data,这种情况怎么处理 about wxpage HOT 1 CLOSED

dev4shane avatar dev4shane commented on May 26, 2024
putData 在异步请求的回调里,如果请求回调比onload调用慢,onload里就取不到data,这种情况怎么处理

from wxpage.

Comments (1)

switer avatar switer commented on May 26, 2024

putData 常用的是存一个Promise实例,存的动作是同步的,在onload可以取到,具体的数据可以通过promise的then回调拿到,代码示例:

putData('key', new Promise(resolve=>{
    request((data)=> {
        resolve(data)
    })
}))


// onLoad
var fetcher = takeData('key')
fetcher.then(data=>{
   // Do something
})

from wxpage.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.