Last active
February 23, 2017 08:48
-
-
Save fuchao2012/6a4db9d86af7a12c1795f46593052987 to your computer and use it in GitHub Desktop.
promise-fetch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let fetch = ()=>{ | |
return new Promise((resolve, reject)=>{ | |
api.call('fetch_data', (err, data)=>{ | |
if(err) return reject(err) | |
resolve(data) | |
}) | |
}) | |
} | |
fetch('data/url/to') | |
.then(res=> res.json()) | |
.then(data=>vm.data = data) | |
.catch(err=>console.error(err)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment