async/await
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
|
ログイン
]
開始行:
[[Vue]]
&color(red){※前提条件:本文基于 Vue 2.0 创作};
#contents
* 概要 [#nd5552ca]
用async/await 来处理异步
语法很简单,就是在函数前面加上async,他就成异步函数啦。怎...
#codeprettify{{
async function hello(){
return 'hello world';
}
}}
* 错误 [#n93dbe2f]
** await is a reserved word [#q5bf4ae7]
#codeprettify{{
function funcA(ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}
//正确应该在 forEach 里面设置 async
function succ(){
let arr =["a","b"];
arr.forEach(async val=>{
await funcA(2000);
console.log(val);
})
}
}}
#hr();
コメント:
#comment_kcaptcha
終了行:
[[Vue]]
&color(red){※前提条件:本文基于 Vue 2.0 创作};
#contents
* 概要 [#nd5552ca]
用async/await 来处理异步
语法很简单,就是在函数前面加上async,他就成异步函数啦。怎...
#codeprettify{{
async function hello(){
return 'hello world';
}
}}
* 错误 [#n93dbe2f]
** await is a reserved word [#q5bf4ae7]
#codeprettify{{
function funcA(ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}
//正确应该在 forEach 里面设置 async
function succ(){
let arr =["a","b"];
arr.forEach(async val=>{
await funcA(2000);
console.log(val);
})
}
}}
#hr();
コメント:
#comment_kcaptcha
ページ名: