From 676064bef3740e3bb00375c868578d8f0896ab21 Mon Sep 17 00:00:00 2001 From: lizhongyi Date: Mon, 29 Jul 2024 10:02:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Eclass=20setter=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E6=B5=8B=E8=AF=95=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/SyntaxCase/index.uvue | 27 +++++++++++++++++---- pages/SyntaxCase/index.vue | 27 +++++++++++++++++---- uni_modules/uts-syntaxcase/utssdk/index.uts | 18 +++++++++++++- 3 files changed, 61 insertions(+), 11 deletions(-) diff --git a/pages/SyntaxCase/index.uvue b/pages/SyntaxCase/index.uvue index 73821e3..e3322db 100644 --- a/pages/SyntaxCase/index.uvue +++ b/pages/SyntaxCase/index.uvue @@ -50,7 +50,9 @@ 测试return:{{ format(testUtsClassInstanceResult['return']) }} 测试success:{{ format(testUtsClassInstanceResult['success']) }} 测试complete:{{ format(testUtsClassInstanceResult['complete']) }} - 测试callback:{{ format(testUtsClassInstanceResult['callback']) }} + 测试callback:{{ format(testUtsClassInstanceResult['callback']) }} + + 测试setter:{{ format(testUtsClassSetterResult) }} @@ -68,7 +70,8 @@ SyncOptions, testAsyncParam3, Test, - request, + request, + SetterTest, } from "../../uni_modules/uts-syntaxcase"; // #endif let test:Test|null = null @@ -131,7 +134,8 @@ fail: null, complete: null, callback: null - } + }, + testUtsClassSetterResult: null, } }, methods: { @@ -156,7 +160,8 @@ this.testUtsClassProp(); this.testUtsClassSyncWithCallback(); this.testUtsClassAsync(); - this.testUtsClassInstance(); + this.testUtsClassInstance(); + this.testUtsClassSetter(); }, testUtsSync() { this.testUtsSyncResult = false; @@ -424,7 +429,19 @@ if (res === 'sync') { this.testUtsClassInstanceResult['return'] = true; } - } + }, + testUtsClassSetter() { + this.testUtsClassSetterResult = false; + try { + let obj = new SetterTest() + obj.nickName = "Tom"; + if (obj.nickName == "Tom") { + this.testUtsClassSetterResult = true; + } + } catch (e) { + console.error("testUtsClassSetter", e); + } + }, } } \ No newline at end of file diff --git a/pages/SyntaxCase/index.vue b/pages/SyntaxCase/index.vue index 6951915..1940464 100644 --- a/pages/SyntaxCase/index.vue +++ b/pages/SyntaxCase/index.vue @@ -49,7 +49,9 @@ 测试return:{{ format(testUtsClassInstanceResult.return) }} 测试success:{{ format(testUtsClassInstanceResult.success) }} 测试complete:{{ format(testUtsClassInstanceResult.complete) }} - 测试callback:{{ format(testUtsClassInstanceResult.callback) }} + 测试callback:{{ format(testUtsClassInstanceResult.callback) }} + + 测试setter:{{ format(testUtsClassSetterResult) }} @@ -62,7 +64,8 @@ testAsync, testAsyncParam3, Test, - request, + request, + SetterTest, } from "../../uni_modules/uts-syntaxcase"; // #endif let test @@ -125,7 +128,8 @@ fail: null, complete: null, callback: null - } + }, + testUtsClassSetterResult: null, } }, methods: { @@ -144,7 +148,8 @@ this.testUtsClassProp(); this.testUtsClassSyncWithCallback(); this.testUtsClassAsync(); - this.testUtsClassInstance(); + this.testUtsClassInstance(); + this.testUtsClassSetter(); }, testUtsSync() { this.testUtsSyncResult = false; @@ -405,7 +410,19 @@ if (res === 'sync') { this.testUtsClassInstanceResult.return = true; } - } + }, + testUtsClassSetter() { + this.testUtsClassSetterResult = false; + try { + let obj = new SetterTest() + obj.nickName = "Tom"; + if (obj.nickName == "Tom") { + this.testUtsClassSetterResult = true; + } + } catch (e) { + console.error("testUtsClassSetter", e); + } + }, } } \ No newline at end of file diff --git a/uni_modules/uts-syntaxcase/utssdk/index.uts b/uni_modules/uts-syntaxcase/utssdk/index.uts index 1c887a9..60350dd 100644 --- a/uni_modules/uts-syntaxcase/utssdk/index.uts +++ b/uni_modules/uts-syntaxcase/utssdk/index.uts @@ -100,7 +100,8 @@ export async function testAsyncParam3(id : number, name : string, opts : AsyncOp export class Test { id : number; - name : string; + name : string; + static type : string = "Test"; constructor(id : number, options : TestOptions) { this.id = id; @@ -121,6 +122,21 @@ export class Test { const res = await testAsync(opts); return res; } +} + +export class SetterTest { + + private _nickName: string = ''; + + get nickName (): string { + console.log('get nickName'); + return this._nickName; + } + set nickName (value: string) { + console.log('set nickName'); + this._nickName = value; + } + } class RequestTaskImpl implements RequestTask { -- GitLab