提交 09fdc64a 编写于 作者: 杜庆泉's avatar 杜庆泉

增加async 多个参数的示例

上级 b2458cd5
......@@ -14,6 +14,10 @@
<view>测试return:{{ format(testUtsAsyncResult.return) }}</view>
<view>测试success:{{ format(testUtsAsyncResult.success) }}</view>
<view>测试complete:{{ format(testUtsAsyncResult.complete) }}</view>
<button @click="testUtsAsyncMulitParam">点击测试uts异步方法-多参数</button>
<view>测试return:{{ format(testUtsAsyncMulitParamResult.return) }}</view>
<view>测试success:{{ format(testUtsAsyncMulitParamResult.success) }}</view>
<view>测试complete:{{ format(testUtsAsyncMulitParamResult.complete) }}</view>
<button @click="testUtsClassConstructor">点击测试uts class构造函数</button>
<view>测试callback:{{ format(testUtsClassConstructorResult.callback) }}</view>
<button @click="testUtsClassStaticProp">点击测试uts class静态属性</button>
......@@ -56,6 +60,7 @@
testSync,
testSyncWithCallback,
testAsync,
testAsyncParam3,
Test,
request,
} from "../../uni_modules/uts-syntaxcase";
......@@ -78,6 +83,12 @@
fail: null,
complete: null,
},
testUtsAsyncMulitParamResult: {
return: null,
success: null,
fail: null,
complete: null,
},
testUtsClassConstructorResult: {
callback: null
},
......@@ -125,6 +136,7 @@
this.testUtsSync();
this.testUtsSyncWithCallback();
this.testUtsAsync();
this.testUtsAsyncMulitParam()
this.testUtsClassConstructor();
this.testUtsClassStaticProp();
this.testUtsClassStaticSyncWithCallback();
......@@ -196,6 +208,31 @@
}
} catch (e) {}
},
async testUtsAsyncMulitParam() {
this.testUtsAsyncMulitParamResult.return = false;
this.testUtsAsyncMulitParamResult.success = false;
// testUtsAsyncResult.fail = false;
this.testUtsAsyncMulitParamResult.complete = false;
try {
const res = await testAsyncParam3(100,"hello",{
type: "success",
success: (res) => {
console.log("testUtsAsyncMulitParam.success.callback", res);
this.testUtsAsyncMulitParamResult.success = true;
},
fail: (res) => {
console.log("testUtsAsyncMulitParam.fail.callback", res);
},
complete: (res) => {
console.log("testUtsAsyncMulitParam.complete.callback", res);
this.testUtsAsyncMulitParamResult.complete = true;
},
});
if (res.name === "testUtsAsyncMulitParam") {
this.testUtsAsyncMulitParamResult.return = true;
}
} catch (e) {}
},
testUtsClassConstructor() {
this.testUtsClassConstructorResult.callback = false
id++
......
......@@ -97,6 +97,24 @@ export async function testAsync(opts : AsyncOptions) : Promise<SyntaxResult> {
// return { name: "testAsync" };
}
export async function testAsyncParam3(id:number,name:string,opts : AsyncOptions) : Promise<SyntaxResult> {
console.log("id",id,"name",name)
if (opts.type == "success") {
opts.success("success");
} else {
opts.fail("fail");
}
opts.complete("complete");
const res : SyntaxResult = {
name: "testUtsAsyncMulitParam"
}
return await testAwaitPromise(res);
// return { name: "testAsync" };
}
export type TestOptions = {
name : string;
callback : (res : string) => void;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册