async / await
2019-12-31 本文已影响0人
小马哒哒哒哒哒哒
let time = () => {
return new Promise((resolve,reject) => {
setTimeout(() => {
resolve('{"name":[1,2]}')
},500)
})
}
let fn = async () => {
try{
let objstr = await time();
console.log(JSON.parse(objstr));
}catch(e){
throw new Error('对象字符串的 key 只能用双引号, 外部使用单引号')
}
}
fn();
async await promise.png