async/await
作者:互联网
这是ES7的语法,它是基于generator函数做的语法糖。
async function 函数名(){ let obj = await getName() return obj } 函数名().then(res=>{ //得到函数的返回值 })
<script src="./04数据.js"></script> </head> <body> </body> <script> // function* initData() { // let categoryList = yield getShopCategory() // let goods = yield getGoods(categoryList[0].id); // let comment = yield getComment(goods[0].id) // return comment // } async function initData(){ let categoryList = await getShopCategory() let goods = await getGoods(categoryList[0].id); let comment = await getComment(goods[0].id) return comment } initData().then(res=>{ console.log(res) })
标签:comment,goods,await,let,async,categoryList,id 来源: https://www.cnblogs.com/guirong/p/13611130.html