最近在做树鱼的项目, 联想到 如果用 async await 怎么处理,
export async function Test1() {
return new Promise((resolve) => {
setTimeout(() => {
resolve('Test1');
}, 1000);
});
}
export async function Test2() {
var test1 = await Test1();
return new Promise((resolve) => {
setTimeout(() => {
resolve(test1+' Test2');
}, 1000);
});
}
在model里调用的时候可以这么写
*getBasicInfo(action, {call, put}) {
const Test2 = yield call(accountService.Test2);
console.log(Test2);
})
这样就可以读取到Test2函数返回的值 "Test1 Test2"