{"id":108034,"date":"2026-09-20T19:50:15","date_gmt":"2026-09-20T11:50:15","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/108034.html"},"modified":"2026-09-20T19:50:15","modified_gmt":"2026-09-20T11:50:15","slug":"harmonyos-arkts-%e9%9b%b6%e5%9f%ba%e7%a1%80%e8%af%ad%e6%b3%95%e8%ae%b2%e4%b9%89%ef%bc%9a%e4%bb%8e%e7%ac%ac%e4%b8%80%e8%a1%8c%e4%bb%a3%e7%a0%81%e5%88%b0%e5%8f%af%e8%bf%90%e8%a1%8c%e9%a1%b5%e9%9d%a2","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/108034.html","title":{"rendered":"HarmonyOS ArkTS \u96f6\u57fa\u7840\u8bed\u6cd5\u8bb2\u4e49\uff1a\u4ece\u7b2c\u4e00\u884c\u4ee3\u7801\u5230\u53ef\u8fd0\u884c\u9875\u9762"},"content":{"rendered":"<h2>0.\u5148\u5efa\u7acb\u6b63\u786e\u8ba4\u8bc6&#xff1a;ArkTS\u3001TypeScript \u4e0e ArkUI \u5206\u522b\u662f\u4ec0\u4e48<\/h2>\n<p>\u521d\u5b66 HarmonyOS \u65f6&#xff0c;\u6700\u5bb9\u6613\u6df7\u6dc6\u7684\u6709\u4e09\u4e2a\u540d\u8bcd&#xff1a;<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260920115012-6aafc874d88c0.png\" alt=\"\u540d\u79f0\u4f60\u53ef\u4ee5\u628a\u5b83\u7406\u89e3\u4e3a\u4e3b\u8981\u89e3\u51b3\u7684\u95ee\u9898\nJavaScript\u57fa\u7840\u7f16\u7a0b\u8bed\u8a00\u201c\u8ba9\u7a0b\u5e8f\u505a\u4e8b\u201d\nTypeScriptJavaScript \u52a0\u4e0a\u7c7b\u578b\u68c0\u67e5\u201c\u8ba9\u4ee3\u7801\u66f4\u4e0d\u5bb9\u6613\u5199\u9519\u201d\nArkTSHarmonyOS \u9762\u5411\u5e94\u7528\u5f00\u53d1\u7684 TypeScript \u65b9\u8a00\u201c\u7528\u66f4\u89c4\u8303\u3001\u66f4\u5b89\u5168\u7684\u65b9\u5f0f\u5199 HarmonyOS \u4ee3\u7801\u201d\nArkUIHarmonyOS \u7684\u58f0\u660e\u5f0f UI \u6846\u67b6\u201c\u628a\u6570\u636e\u753b\u6210\u9875\u9762\uff0c\u5e76\u54cd\u5e94\u7528\u6237\u70b9\u51fb\u201d\" \/><\/p>\n<p>\u4e00\u53e5\u8bdd\u8bb0\u5fc6&#xff1a;<br \/>\n\u2022 ArkTS \u662f\u5199\u903b\u8f91\u3001\u7c7b\u578b\u548c\u6570\u636e\u7684\u8bed\u8a00\u3002<br \/>\n\u2022 ArkUI \u662f\u7528 ArkTS \u63cf\u8ff0\u754c\u9762\u7684\u65b9\u5f0f\u3002<br \/>\n\u2022 \u4f60\u5728 .ets \u6587\u4ef6\u91cc\u901a\u5e38\u4f1a\u540c\u65f6\u5199\u201c\u6570\u636e\u5904\u7406\u4ee3\u7801\u201d\u548c\u201c\u9875\u9762\u4ee3\u7801\u201d\u3002<br \/>\n\u4f8b\u5982&#xff1a;<\/p>\n<p>let userName: string &#061; &#039;\u5c0f\u660e&#039;; \/\/ ArkTS&#xff1a;\u5b9a\u4e49\u6570\u636e<\/p>\n<p>Text(&#096;\u4f60\u597d&#xff0c;${userName}&#096;) \/\/ ArkUI&#xff1a;\u628a\u6570\u636e\u753b\u5230\u5c4f\u5e55\u4e0a<\/p>\n<h2>1. \u7b2c\u4e00\u4e2a\u9875\u9762\u957f\u4ec0\u4e48\u6837<\/h2>\n<p>\u6253\u5f00\u65b0\u9879\u76ee\u4e2d\u7684 Index.ets&#xff0c;\u5e38\u4f1a\u770b\u5230\u7c7b\u4f3c\u4e0b\u9762\u7684\u7ed3\u6784&#xff1a;<\/p>\n<p>&#064;Entry<br \/>\n&#064;Component<br \/>\nstruct Index {<br \/>\n  &#064;State message: string &#061; &#039;\u4f60\u597d&#xff0c;ArkTS&#xff01;&#039;<\/p>\n<p>  build() {<br \/>\n    Column() {<br \/>\n      Text(this.message)<br \/>\n        .fontSize(28)<\/p>\n<p>      Button(&#039;\u70b9\u6211&#039;)<br \/>\n        .margin({ top: 16 })<br \/>\n        .onClick(() &#061;&gt; {<br \/>\n          this.message &#061; &#039;\u4f60\u521a\u521a\u70b9\u51fb\u4e86\u6309\u94ae&#039;<br \/>\n        })<br \/>\n    }<br \/>\n    .width(&#039;100%&#039;)<br \/>\n    .height(&#039;100%&#039;)<br \/>\n    .justifyContent(FlexAlign.Center)<br \/>\n  }<br \/>\n}<\/p>\n<p>\u8fd0\u884c\u540e&#xff0c;\u9875\u9762\u4e0a\u4f1a\u663e\u793a\u4e00\u53e5\u6587\u5b57\u548c\u4e00\u4e2a\u6309\u94ae\u3002\u70b9\u51fb\u6309\u94ae&#xff0c;\u6587\u5b57\u4f1a\u6539\u53d8\u3002<br \/>\n\u5148\u4e0d\u8981\u6025\u7740\u8bb0\u4f4f\u5168\u90e8\u8bed\u6cd5\u3002\u4f60\u53ea\u8981\u5148\u7406\u89e3\u8fd9\u56db\u4ef6\u4e8b&#xff1a;<\/p>\n<li>struct Index&#xff1a;\u5b9a\u4e49\u4e00\u4e2a\u53eb Index \u7684\u9875\u9762\u7ec4\u4ef6\u3002<\/li>\n<li>&#064;State message&#xff1a;\u5b9a\u4e49\u4f1a\u5f71\u54cd\u9875\u9762\u663e\u793a\u7684\u6570\u636e\u3002<\/li>\n<li>build()&#xff1a;\u63cf\u8ff0\u9875\u9762\u201c\u5e94\u8be5\u957f\u4ec0\u4e48\u6837\u201d\u3002<\/li>\n<li>onClick&#xff1a;\u63cf\u8ff0\u7528\u6237\u70b9\u51fb\u6309\u94ae\u540e\u201c\u5e94\u8be5\u505a\u4ec0\u4e48\u201d\u3002<\/li>\n<h3>1.1 &#064;Entry&#xff1a;\u5e94\u7528\u5165\u53e3\u9875\u9762<\/h3>\n<p>&#064;Entry<br \/>\n&#064;Component<br \/>\nstruct Index {<br \/>\n  build() {<br \/>\n    Text(&#039;\u6211\u662f\u5e94\u7528\u542f\u52a8\u540e\u6700\u5148\u663e\u793a\u7684\u9875\u9762&#039;)<br \/>\n  }<br \/>\n}<\/p>\n<p>&#064;Entry \u8868\u793a&#xff1a;\u8fd9\u4e2a\u7ec4\u4ef6\u662f\u4e00\u4e2a\u9875\u9762\u5165\u53e3\u3002\u4e00\u4e2a\u9875\u9762\u6587\u4ef6\u901a\u5e38\u53ea\u9700\u8981\u4e00\u4e2a &#064;Entry \u7ec4\u4ef6\u3002<\/p>\n<h3>1.2 &#064;Component&#xff1a;\u8fd9\u662f\u4e00\u4e2a UI \u7ec4\u4ef6<\/h3>\n<p>&#064;Component<br \/>\nstruct WelcomeCard {<br \/>\n  build() {<br \/>\n    Text(&#039;\u6b22\u8fce\u5b66\u4e60 ArkTS&#039;)<br \/>\n  }<br \/>\n}<\/p>\n<p>\u6709\u4e86 &#064;Component&#xff0c;ArkUI \u624d\u77e5\u9053\u8fd9\u4e2a struct \u4e0d\u662f\u666e\u901a\u6570\u636e\u7ed3\u6784&#xff0c;\u800c\u662f\u4e00\u4e2a\u53ef\u7ed8\u5236\u5230\u5c4f\u5e55\u4e0a\u7684\u7ec4\u4ef6\u3002<\/p>\n<h3>1.3 build()&#xff1a;\u9875\u9762\u7684\u201c\u8bf4\u660e\u4e66\u201d<\/h3>\n<p>\u5728 build() \u4e2d&#xff0c;\u4f60\u4e0d\u662f\u624b\u5de5\u521b\u5efa\u50cf\u7d20&#xff0c;\u800c\u662f\u5728\u58f0\u660e&#xff1a;<br \/>\n\u9875\u9762\u91cc\u6709\u54ea\u4e9b\u7ec4\u4ef6&#xff0c;\u5b83\u4eec\u6309\u4ec0\u4e48\u987a\u5e8f\u6392\u5217&#xff0c;\u4f7f\u7528\u4ec0\u4e48\u6570\u636e&#xff0c;\u62e5\u6709\u600e\u6837\u7684\u6837\u5f0f\u3002<\/p>\n<p>build() {<br \/>\n  Column() {<br \/>\n    Text(&#039;\u7b2c\u4e00\u884c&#039;)<br \/>\n    Text(&#039;\u7b2c\u4e8c\u884c&#039;)<br \/>\n    Button(&#039;\u7b2c\u4e09\u4e2a\u63a7\u4ef6&#039;)<br \/>\n  }<br \/>\n}<\/p>\n<p>\u8fd9\u6bb5\u4ee3\u7801\u8868\u793a\u7eb5\u5411\u6392\u5217&#xff1a;<\/p>\n<p>\u7b2c\u4e00\u884c<br \/>\n\u7b2c\u4e8c\u884c<br \/>\n[\u7b2c\u4e09\u4e2a\u63a7\u4ef6]<\/p>\n<h2>2. \u6ce8\u91ca&#xff1a;\u7ed9\u672a\u6765\u7684\u81ea\u5df1\u5199\u8bf4\u660e<\/h2>\n<p>\u6ce8\u91ca\u4e0d\u4f1a\u6267\u884c&#xff0c;\u53ea\u662f\u89e3\u91ca\u4ee3\u7801\u3002<\/p>\n<p>\/\/ \u5355\u884c\u6ce8\u91ca&#xff1a;\u8fd9\u4e00\u884c\u4e0d\u4f1a\u6267\u884c<\/p>\n<p>\/*<br \/>\n  \u591a\u884c\u6ce8\u91ca&#xff1a;<br \/>\n  \u53ef\u4ee5\u5199\u5f88\u591a\u884c\u8bf4\u660e\u3002<br \/>\n*\/<\/p>\n<p>\u63a8\u8350\u517b\u6210\u4e24\u4e2a\u4e60\u60ef&#xff1a;<br \/>\n\u2022 \u5bf9\u201c\u4e3a\u4ec0\u4e48\u8fd9\u6837\u5199\u201d\u6dfb\u52a0\u6ce8\u91ca\u3002<br \/>\n\u2022 \u4e0d\u8981\u7ed9\u663e\u800c\u6613\u89c1\u7684\u8bed\u53e5\u6dfb\u52a0\u65e0\u610f\u4e49\u6ce8\u91ca\u3002<br \/>\n\u4e0d\u592a\u6709\u5e2e\u52a9&#xff1a;<\/p>\n<p>let age: number &#061; 18; \/\/ \u5b9a\u4e49\u5e74\u9f84<\/p>\n<p>\u66f4\u6709\u5e2e\u52a9&#xff1a;<\/p>\n<p>\/\/ \u8ba2\u5355\u91d1\u989d\u4ee5\u201c\u5206\u201d\u4e3a\u5355\u4f4d\u4fdd\u5b58&#xff0c;\u907f\u514d\u6d6e\u70b9\u6570\u8ba1\u7b97\u8bef\u5dee<br \/>\nlet amountInFen: number &#061; 1999;<\/p>\n<h2>3. \u53d8\u91cf&#xff1a;\u8ba9\u7a0b\u5e8f\u8bb0\u4f4f\u6570\u636e<\/h2>\n<p>\u53d8\u91cf\u53ef\u4ee5\u7406\u89e3\u4e3a\u201c\u6709\u540d\u5b57\u7684\u76d2\u5b50\u201d\u3002\u4f60\u628a\u6570\u636e\u653e\u8fdb\u76d2\u5b50&#xff0c;\u540e\u7eed\u901a\u8fc7\u540d\u5b57\u53d6\u51fa\u6765\u3002<br \/>\nArkTS \u4e2d\u6700\u5e38\u7528\u7684\u53d8\u91cf\u58f0\u660e\u65b9\u5f0f\u662f let \u548c const\u3002<\/p>\n<p>let score: number &#061; 60;<br \/>\nscore &#061; 95;<\/p>\n<p>const appName: string &#061; &#039;\u5b66\u4e60\u52a9\u624b&#039;;<br \/>\n\/\/ appName &#061; &#039;\u65b0\u540d\u79f0&#039;; \/\/ \u9519\u8bef&#xff1a;const \u58f0\u660e\u7684\u53d8\u91cf\u4e0d\u80fd\u91cd\u65b0\u8d4b\u503c<\/p>\n<h3>3.1 let \u548c const \u600e\u4e48\u9009<\/h3>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260920115013-6aafc8750b4eb.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>let page: number &#061; 1;<br \/>\npage &#061; 2;<\/p>\n<p>const maxPageSize: number &#061; 20;<\/p>\n<p>\u521d\u5b66\u65f6\u53ef\u4ee5\u91c7\u7528\u7b80\u5355\u89c4\u5219&#xff1a;<br \/>\n\u9ed8\u8ba4\u5148\u5199 const&#xff1b;\u53ea\u6709\u786e\u5b9e\u9700\u8981\u6539\u53d8\u53d8\u91cf\u503c\u65f6&#xff0c;\u624d\u4f7f\u7528 let\u3002<\/p>\n<h3>3.2 \u4e0d\u63a8\u8350\u968f\u610f\u4f7f\u7528 var<\/h3>\n<p>\u4f60\u53ef\u80fd\u4f1a\u5728\u65e7 JavaScript \u6559\u7a0b\u4e2d\u770b\u5230 var&#xff1a;<br \/>\nvar oldStyle: string &#061; \u2018\u65e7\u5199\u6cd5\u2019;<br \/>\n\u73b0\u4ee3 ArkTS \u5f00\u53d1\u4e2d\u4f18\u5148\u4f7f\u7528 let \u548c const\u3002\u5b83\u4eec\u7684\u4f5c\u7528\u8303\u56f4\u66f4\u6e05\u695a&#xff0c;\u66f4\u4e0d\u5bb9\u6613\u4ea7\u751f\u96be\u4ee5\u6392\u67e5\u7684\u9519\u8bef\u3002<\/p>\n<h2>4. \u57fa\u672c\u6570\u636e\u7c7b\u578b&#xff1a;\u7ed9\u6570\u636e\u8d34\u4e0a\u201c\u6807\u7b7e\u201d<\/h2>\n<p>\u7c7b\u578b\u544a\u8bc9\u7f16\u8bd1\u5668&#xff1a;\u8fd9\u4e2a\u53d8\u91cf\u91cc\u51c6\u5907\u88c5\u4ec0\u4e48\u6570\u636e\u3002<\/p>\n<p>let name: string &#061; &#039;\u5c0f\u534e&#039;;<br \/>\nlet age: number &#061; 18;<br \/>\nlet isStudent: boolean &#061; true;<\/p>\n<h3>4.1 string&#xff1a;\u6587\u672c<\/h3>\n<p>\u6587\u672c\u5fc5\u987b\u7528\u5355\u5f15\u53f7\u3001\u53cc\u5f15\u53f7\u6216\u53cd\u5f15\u53f7\u5305\u8d77\u6765\u3002<\/p>\n<p>let city: string &#061; &#039;\u6df1\u5733&#039;;<br \/>\nlet school: string &#061; &#034;\u9e3f\u8499\u5b66\u9662&#034;;<br \/>\nlet greeting: string &#061; &#096;\u6b22\u8fce\u6765\u5230 ${city}&#096;;<\/p>\n<p>\u63a8\u8350\u4f7f\u7528\u6a21\u677f\u5b57\u7b26\u4e32&#xff08;\u53cd\u5f15\u53f7&#xff09;\u62fc\u63a5\u6587\u672c&#xff1a;<\/p>\n<p>let userName: string &#061; &#039;\u5c0f\u534e&#039;;<br \/>\nlet age: number &#061; 18;<\/p>\n<p>let text: string &#061; &#096;\u6211\u662f${userName}&#xff0c;\u4eca\u5e74${age}\u5c81\u3002&#096;;<\/p>\n<p>\u4e0d\u63a8\u8350\u521d\u5b66\u65f6\u5927\u91cf\u4f7f\u7528 &#043; \u62fc\u63a5&#xff1a;<br \/>\nlet text: string &#061; \u2018\u6211\u662f\u2019 &#043; userName &#043; \u2018&#xff0c;\u4eca\u5e74\u2019 &#043; age &#043; \u2018\u5c81\u3002\u2019;<br \/>\n\u6a21\u677f\u5b57\u7b26\u4e32\u53ef\u8bfb\u6027\u66f4\u597d\u3002<br \/>\n\u5e38\u7528\u6587\u672c\u64cd\u4f5c&#xff1a;<\/p>\n<p>let title: string &#061; &#039;  ArkTS \u5165\u95e8  &#039;;<\/p>\n<p>let length: number &#061; title.length;          \/\/ \u6587\u672c\u957f\u5ea6<br \/>\nlet upper: string &#061; title.toUpperCase();    \/\/ \u8f6c\u5927\u5199<br \/>\nlet lower: string &#061; title.toLowerCase();    \/\/ \u8f6c\u5c0f\u5199<br \/>\nlet clean: string &#061; title.trim();           \/\/ \u53bb\u6389\u9996\u5c3e\u7a7a\u683c<br \/>\nlet hasArk: boolean &#061; title.includes(&#039;Ark&#039;); \/\/ \u662f\u5426\u5305\u542b\u67d0\u6587\u672c<\/p>\n<h3>4.2 number&#xff1a;\u6570\u5b57<\/h3>\n<p>number \u53ef\u8868\u793a\u6574\u6570\u548c\u5c0f\u6570\u3002<\/p>\n<p>let count: number &#061; 10;<br \/>\nlet price: number &#061; 19.9;<br \/>\nlet total: number &#061; count * price;<\/p>\n<p>\u5e38\u89c1\u8fd0\u7b97\u7b26&#xff1a;<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260920115013-6aafc87529e72.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>let apples: number &#061; 10;<br \/>\napples &#061; apples &#043; 1;<br \/>\napples &#043;&#061; 1; \/\/ \u7b49\u4ef7\u4e8e apples &#061; apples &#043; 1<\/p>\n<h3>4.3 boolean&#xff1a;\u771f\u6216\u5047<\/h3>\n<p>\u5e03\u5c14\u503c\u53ea\u6709\u4e24\u4e2a&#xff1a;<\/p>\n<p>let isLogin: boolean &#061; true;<br \/>\nlet isVip: boolean &#061; false;<\/p>\n<p>\u6ce8\u610f&#xff1a;true \u548c false \u4e0d\u8981\u52a0\u5f15\u53f7\u3002\u52a0\u4e86\u5f15\u53f7\u540e\u5b83\u4eec\u4f1a\u53d8\u6210\u6587\u672c\u3002<\/p>\n<p>let correct: boolean &#061; true;<br \/>\nlet wrong: string &#061; &#039;true&#039;;<\/p>\n<h3>4.4 undefined \u4e0e null&#xff1a;\u6ca1\u6709\u503c&#xff0c;\u8981\u8c28\u614e\u5904\u7406<\/h3>\n<p>\u521d\u5b66\u9636\u6bb5\u6700\u91cd\u8981\u7684\u539f\u5219\u662f&#xff1a;<br \/>\n\u4e0d\u786e\u5b9a\u6570\u636e\u662f\u5426\u5b58\u5728\u65f6&#xff0c;\u5148\u68c0\u67e5&#xff0c;\u518d\u4f7f\u7528\u3002<\/p>\n<p>let nickName: string | undefined &#061; undefined;<\/p>\n<p>if (nickName !&#061;&#061; undefined) {<br \/>\n  console.info(nickName.toUpperCase());<br \/>\n} else {<br \/>\n  console.info(&#039;\u7528\u6237\u5c1a\u672a\u8bbe\u7f6e\u6635\u79f0&#039;);<br \/>\n}<\/p>\n<p>string | undefined \u7684\u610f\u601d\u662f&#xff1a;\u8fd9\u4e2a\u53d8\u91cf\u8981\u4e48\u662f\u6587\u672c&#xff0c;\u8981\u4e48\u6ca1\u6709\u503c\u3002<\/p>\n<h2>5. \u7c7b\u578b\u63a8\u65ad&#xff1a;\u6709\u65f6\u53ef\u4ee5\u4e0d\u624b\u5199\u7c7b\u578b<\/h2>\n<p>\u5982\u679c\u53f3\u4fa7\u7684\u503c\u975e\u5e38\u660e\u786e&#xff0c;ArkTS \u901a\u5e38\u53ef\u4ee5\u81ea\u52a8\u63a8\u65ad\u7c7b\u578b&#xff1a;<\/p>\n<p>let name &#061; &#039;\u5c0f\u660e&#039;;    \/\/ \u63a8\u65ad\u4e3a string<br \/>\nlet age &#061; 20;         \/\/ \u63a8\u65ad\u4e3a number<br \/>\nlet isReady &#061; true;   \/\/ \u63a8\u65ad\u4e3a boolean<\/p>\n<p>\u4e0d\u8fc7\u5728\u5b66\u4e60\u9636\u6bb5\u3001\u51fd\u6570\u53c2\u6570\u3001\u5bf9\u8c61\u7ed3\u6784\u3001\u63a5\u53e3\u8fb9\u754c\u5904&#xff0c;\u5efa\u8bae\u660e\u786e\u5199\u51fa\u7c7b\u578b&#xff1a;<\/p>\n<p>let courseName: string &#061; &#039;ArkTS&#039;;<br \/>\nlet lessonCount: number &#061; 12;<\/p>\n<p>\u8fd9\u6837\u4f60\u81ea\u5df1\u548c\u7f16\u8bd1\u5668\u90fd\u66f4\u5bb9\u6613\u53d1\u73b0\u95ee\u9898\u3002<\/p>\n<h2>6. \u8fd0\u7b97\u4e0e\u6bd4\u8f83&#xff1a;\u7a0b\u5e8f\u5982\u4f55\u201c\u5224\u65ad\u201d<\/h2>\n<h3>6.1 \u6bd4\u8f83\u8fd0\u7b97\u7b26<\/h3>\n<p>let score: number &#061; 85;<\/p>\n<p>console.info(score &gt; 60);   \/\/ true<br \/>\nconsole.info(score &gt;&#061; 85);  \/\/ true<br \/>\nconsole.info(score &lt; 100);  \/\/ true<br \/>\nconsole.info(score &#061;&#061;&#061; 85); \/\/ true<br \/>\nconsole.info(score !&#061;&#061; 85); \/\/ false<\/p>\n<p>\u521d\u5b66\u65f6\u8bf7\u4f18\u5148\u4f7f\u7528\u4e25\u683c\u76f8\u7b49 &#061;&#061;&#061; \u548c\u4e25\u683c\u4e0d\u7b49 !&#061;&#061;\u3002<\/p>\n<p>let value: number &#061; 1;<\/p>\n<p>\/\/ \u63a8\u8350<br \/>\nif (value &#061;&#061;&#061; 1) {<br \/>\n  console.info(&#039;\u503c\u4e3a 1&#039;);<br \/>\n}<\/p>\n<h3>6.2 \u903b\u8f91\u8fd0\u7b97\u7b26<\/h3>\n<p>let age: number &#061; 20;<br \/>\nlet hasTicket: boolean &#061; true;<\/p>\n<p>let canEnter: boolean &#061; age &gt;&#061; 18 &amp;&amp; hasTicket;<br \/>\nlet needsHelp: boolean &#061; age &lt; 18 || !hasTicket;<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260920115013-6aafc8754ec30.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h2>7. \u6761\u4ef6\u5224\u65ad&#xff1a;\u8ba9\u7a0b\u5e8f\u505a\u4e0d\u540c\u9009\u62e9<\/h2>\n<h3>7.1 if \/ else if \/ else<\/h3>\n<p>function getLevel(score: number): string {<br \/>\n  if (score &gt;&#061; 90) {<br \/>\n    return &#039;\u4f18\u79c0&#039;;<br \/>\n  } else if (score &gt;&#061; 60) {<br \/>\n    return &#039;\u53ca\u683c&#039;;<br \/>\n  } else {<br \/>\n    return &#039;\u9700\u8981\u7ee7\u7eed\u52aa\u529b&#039;;<br \/>\n  }<br \/>\n}<\/p>\n<p>\u8c03\u7528&#xff1a;<\/p>\n<p>let result: string &#061; getLevel(85);<br \/>\nconsole.info(result); \/\/ \u53ca\u683c<\/p>\n<p>\u8bfb\u4ee3\u7801\u65f6\u53ef\u4ee5\u6309\u81ea\u7136\u8bed\u8a00\u7406\u89e3&#xff1a;<\/p>\n<p>\u5982\u679c \u5206\u6570\u5927\u4e8e\u7b49\u4e8e 90&#xff1a;\u4f18\u79c0<br \/>\n\u5426\u5219\u5982\u679c \u5206\u6570\u5927\u4e8e\u7b49\u4e8e 60&#xff1a;\u53ca\u683c<br \/>\n\u5426\u5219&#xff1a;\u9700\u8981\u7ee7\u7eed\u52aa\u529b<\/p>\n<h3>7.2 \u4e09\u5143\u8868\u8fbe\u5f0f&#xff1a;\u7b80\u5355\u4e8c\u9009\u4e00<\/h3>\n<p>\u5f53\u5224\u65ad\u53ea\u6709\u4e24\u4e2a\u7ed3\u679c\u65f6\u53ef\u4f7f\u7528&#xff1a;<\/p>\n<p>let isLogin: boolean &#061; true;<br \/>\nlet displayText: string &#061; isLogin ? &#039;\u6b22\u8fce\u56de\u6765&#039; : &#039;\u8bf7\u5148\u767b\u5f55&#039;;<\/p>\n<p>\u683c\u5f0f\u662f&#xff1a;<\/p>\n<p>\u6761\u4ef6 ? \u6761\u4ef6\u6210\u7acb\u65f6\u7684\u503c : \u6761\u4ef6\u4e0d\u6210\u7acb\u65f6\u7684\u503c<\/p>\n<p>\u4e0d\u8981\u628a\u8fc7\u4e8e\u590d\u6742\u7684\u4e1a\u52a1\u903b\u8f91\u585e\u8fdb\u4e09\u5143\u8868\u8fbe\u5f0f&#xff1b;\u590d\u6742\u65f6\u8bf7\u6539\u7528 if\u3002<\/p>\n<h3>7.3 switch&#xff1a;\u591a\u4e2a\u56fa\u5b9a\u9009\u9879<\/h3>\n<p>function getWeekText(day: number): string {<br \/>\n  switch (day) {<br \/>\n    case 1:<br \/>\n      return &#039;\u661f\u671f\u4e00&#039;;<br \/>\n    case 2:<br \/>\n      return &#039;\u661f\u671f\u4e8c&#039;;<br \/>\n    case 3:<br \/>\n      return &#039;\u661f\u671f\u4e09&#039;;<br \/>\n    default:<br \/>\n      return &#039;\u5176\u4ed6\u65e5\u671f&#039;;<br \/>\n  }<br \/>\n}<\/p>\n<p>\u5f53\u4f60\u662f\u5728\u6bd4\u8f83\u201c\u4e00\u4e2a\u503c\u5bf9\u5e94\u591a\u4e2a\u56fa\u5b9a\u60c5\u51b5\u201d\u65f6&#xff0c;switch \u5f88\u5408\u9002\u3002<\/p>\n<h2>8. \u5faa\u73af&#xff1a;\u91cd\u590d\u505a\u4e00\u4ef6\u4e8b<\/h2>\n<h3>8.1 for \u5faa\u73af<\/h3>\n<p>for (let index: number &#061; 1; index &lt;&#061; 5; index&#043;&#043;) {<br \/>\n  console.info(&#096;\u7b2c ${index} \u6b21\u7ec3\u4e60&#096;);<br \/>\n}<\/p>\n<p>\u5b83\u7531\u4e09\u90e8\u5206\u7ec4\u6210&#xff1a;<\/p>\n<p>for (\u521d\u59cb\u5316; \u7ee7\u7eed\u6761\u4ef6; \u6bcf\u8f6e\u7ed3\u675f\u540e\u7684\u53d8\u5316) {<br \/>\n  \u91cd\u590d\u6267\u884c\u7684\u4ee3\u7801<br \/>\n}<\/p>\n<h3>8.2 \u904d\u5386\u6570\u7ec4&#xff1a;for\u2026of<\/h3>\n<p>let fruits: string[] &#061; [&#039;\u82f9\u679c&#039;, &#039;\u9999\u8549&#039;, &#039;\u6a59\u5b50&#039;];<\/p>\n<p>for (const fruit of fruits) {<br \/>\n  console.info(fruit);<br \/>\n}<\/p>\n<p>\u5bf9\u4e8e\u521d\u5b66\u8005&#xff0c;\u8bfb\u53d6\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e00\u9879\u65f6&#xff0c;\u4f18\u5148\u8003\u8651 for\u2026of\u3002\u5b83\u6bd4\u624b\u52a8\u5199\u4e0b\u6807\u66f4\u76f4\u89c2\u3002<\/p>\n<h3>8.3 while \u5faa\u73af<\/h3>\n<p>let current: number &#061; 1;<\/p>\n<p>while (current &lt;&#061; 3) {<br \/>\n  console.info(&#096;\u5f53\u524d\u503c&#xff1a;${current}&#096;);<br \/>\n  current&#043;&#043;;<br \/>\n}<\/p>\n<p>\u4f7f\u7528 while \u65f6\u4e00\u5b9a\u8981\u786e\u4fdd\u5faa\u73af\u6761\u4ef6\u6700\u7ec8\u4f1a\u53d8\u6210 false&#xff0c;\u5426\u5219\u53ef\u80fd\u51fa\u73b0\u6b7b\u5faa\u73af\u3002<br \/>\n\u9519\u8bef\u793a\u4f8b&#xff1a;<\/p>\n<p>let count: number &#061; 1;<\/p>\n<p>\/\/ \u4e0d\u8981\u8fd0\u884c\u8fd9\u6837\u7684\u4ee3\u7801&#xff1a;count \u6c38\u8fdc\u6ca1\u6709\u53d8\u5316<br \/>\n\/\/ while (count &lt;&#061; 3) {<br \/>\n\/\/   console.info(count);<br \/>\n\/\/ }<\/p>\n<h2>9. \u6570\u7ec4&#xff1a;\u6309\u987a\u5e8f\u4fdd\u5b58\u4e00\u7ec4\u6570\u636e<\/h2>\n<p>\u6570\u7ec4\u7528\u4e8e\u4fdd\u5b58\u591a\u4e2a\u540c\u7c7b\u6570\u636e\u3002<\/p>\n<p>let scores: number[] &#061; [80, 90, 100];<br \/>\nlet names: string[] &#061; [&#039;\u5c0f\u7ea2&#039;, &#039;\u5c0f\u84dd&#039;, &#039;\u5c0f\u7eff&#039;];<\/p>\n<h3>9.1 \u8bfb\u53d6\u6570\u7ec4\u5143\u7d20<\/h3>\n<p>\u6570\u7ec4\u4e0b\u6807\u4ece 0 \u5f00\u59cb&#xff1a;<\/p>\n<p>let cities: string[] &#061; [&#039;\u5317\u4eac&#039;, &#039;\u4e0a\u6d77&#039;, &#039;\u5e7f\u5dde&#039;];<\/p>\n<p>console.info(cities[0]); \/\/ \u5317\u4eac<br \/>\nconsole.info(cities[1]); \/\/ \u4e0a\u6d77<\/p>\n<h3>9.2 \u5e38\u7528\u6570\u7ec4\u64cd\u4f5c<\/h3>\n<p>let tasks: string[] &#061; [&#039;\u5b66\u4e60\u53d8\u91cf&#039;, &#039;\u5b66\u4e60\u51fd\u6570&#039;];<\/p>\n<p>tasks.push(&#039;\u5b66\u4e60\u7ec4\u4ef6&#039;); \/\/ \u672b\u5c3e\u6dfb\u52a0<br \/>\nconsole.info(tasks.length);<\/p>\n<p>let firstTask: string | undefined &#061; tasks.shift(); \/\/ \u5220\u9664\u5e76\u53d6\u5f97\u7b2c\u4e00\u4e2a\u5143\u7d20<br \/>\nconsole.info(firstTask);<\/p>\n<p>\u5728 UI \u72b6\u6001\u4e2d&#xff0c;\u63a8\u8350\u8fd4\u56de\u65b0\u6570\u7ec4&#xff0c;\u800c\u4e0d\u662f\u5c31\u5730\u4fee\u6539\u590d\u6742\u5bf9\u8c61\u3002\u8fd9\u6837\u9875\u9762\u66f4\u65b0\u66f4\u7a33\u5b9a\u3001\u4ee3\u7801\u4e5f\u66f4\u5bb9\u6613\u7406\u89e3&#xff1a;<\/p>\n<p>let oldList: number[] &#061; [1, 2, 3];<br \/>\nlet newList: number[] &#061; oldList.map((item: number) &#061;&gt; item * 2);<\/p>\n<p>\/\/ oldList \u662f [1, 2, 3]<br \/>\n\/\/ newList \u662f [2, 4, 6]<\/p>\n<h3>9.3 \u5e38\u89c1\u6570\u7ec4\u65b9\u6cd5<\/h3>\n<p>let scores: number[] &#061; [60, 75, 90, 100];<\/p>\n<p>let passed: number[] &#061; scores.filter((score: number) &#061;&gt; score &gt;&#061; 60);<br \/>\nlet doubled: number[] &#061; scores.map((score: number) &#061;&gt; score * 2);<br \/>\nlet hasPerfect: boolean &#061; scores.some((score: number) &#061;&gt; score &#061;&#061;&#061; 100);<br \/>\nlet allPassed: boolean &#061; scores.every((score: number) &#061;&gt; score &gt;&#061; 60);<\/p>\n<p>\u5b83\u4eec\u7684\u8bed\u4e49\u662f&#xff1a;<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260920115013-6aafc8756da2c.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h2>10. \u5bf9\u8c61&#xff1a;\u63cf\u8ff0\u4e00\u4ef6\u6709\u591a\u4e2a\u5c5e\u6027\u7684\u4e8b\u7269<\/h2>\n<p>\u5982\u679c\u4e00\u4e2a\u5b66\u751f\u4e0d\u4ec5\u6709\u59d3\u540d&#xff0c;\u8fd8\u6709\u5e74\u9f84\u548c\u662f\u5426\u5df2\u62a5\u540d&#xff0c;\u5c31\u9002\u5408\u7528\u5bf9\u8c61&#xff1a;<\/p>\n<p>let student: {<br \/>\n  name: string;<br \/>\n  age: number;<br \/>\n  enrolled: boolean;<br \/>\n} &#061; {<br \/>\n  name: &#039;\u5c0f\u660e&#039;,<br \/>\n  age: 18,<br \/>\n  enrolled: true<br \/>\n};<\/p>\n<p>console.info(student.name);<br \/>\nconsole.info(student.age);<\/p>\n<p>\u4f46\u5bf9\u8c61\u5b57\u6bb5\u8f83\u591a\u65f6&#xff0c;\u5efa\u8bae\u4f7f\u7528 interface\u3002<\/p>\n<h2>11. interface&#xff1a;\u7ed9\u5bf9\u8c61\u5236\u5b9a\u7edf\u4e00\u7ed3\u6784<\/h2>\n<p>\u63a5\u53e3\u662f\u4e00\u4efd\u201c\u6570\u636e\u7ed3\u6784\u7ea6\u5b9a\u201d\u3002\u5b83\u4e0d\u76f4\u63a5\u521b\u5efa\u5bf9\u8c61&#xff0c;\u800c\u662f\u89c4\u5b9a\u5bf9\u8c61\u5fc5\u987b\u6709\u4ec0\u4e48\u5b57\u6bb5\u3001\u6bcf\u4e2a\u5b57\u6bb5\u662f\u4ec0\u4e48\u7c7b\u578b\u3002<\/p>\n<p>interface Student {<br \/>\n  id: number;<br \/>\n  name: string;<br \/>\n  age: number;<br \/>\n  enrolled: boolean;<br \/>\n}<\/p>\n<p>\u6309\u63a5\u53e3\u521b\u5efa\u5bf9\u8c61&#xff1a;<\/p>\n<p>let student: Student &#061; {<br \/>\n  id: 1,<br \/>\n  name: &#039;\u5c0f\u660e&#039;,<br \/>\n  age: 18,<br \/>\n  enrolled: true<br \/>\n};<\/p>\n<p>\u5982\u679c\u6f0f\u6389\u5b57\u6bb5&#xff0c;\u7f16\u8bd1\u5668\u4f1a\u63d0\u9192\u4f60&#xff1a;<\/p>\n<p>\/\/ \u9519\u8bef\u793a\u610f&#xff1a;\u7f3a\u5c11 enrolled<br \/>\n\/\/ let invalidStudent: Student &#061; {<br \/>\n\/\/   id: 2,<br \/>\n\/\/   name: &#039;\u5c0f\u7ea2&#039;,<br \/>\n\/\/   age: 19<br \/>\n\/\/ };<\/p>\n<h3>11.1 \u53ef\u9009\u5c5e\u6027 ?<\/h3>\n<p>\u6709\u4e9b\u5c5e\u6027\u53ef\u4ee5\u6ca1\u6709&#xff1a;<\/p>\n<p>interface UserProfile {<br \/>\n  id: number;<br \/>\n  name: string;<br \/>\n  avatarUrl?: string;<br \/>\n}<\/p>\n<p>let user: UserProfile &#061; {<br \/>\n  id: 1,<br \/>\n  name: &#039;\u5c0f\u534e&#039;<br \/>\n};<\/p>\n<p>\u8bfb\u53d6\u53ef\u9009\u5c5e\u6027\u65f6\u8981\u515c\u5e95&#xff1a;<\/p>\n<p>let avatarText: string &#061; user.avatarUrl ?? &#039;\u672a\u8bbe\u7f6e\u5934\u50cf&#039;;<br \/>\nconsole.info(avatarText);<\/p>\n<p>?? \u7684\u610f\u601d\u662f&#xff1a;\u5982\u679c\u5de6\u8fb9\u662f null \u6216 undefined&#xff0c;\u5c31\u4f7f\u7528\u53f3\u8fb9\u7684\u9ed8\u8ba4\u503c\u3002<\/p>\n<h2>12. \u51fd\u6570&#xff1a;\u628a\u53ef\u91cd\u590d\u7684\u903b\u8f91\u88c5\u8d77\u6765<\/h2>\n<p>\u51fd\u6570\u76f8\u5f53\u4e8e\u4e00\u4e2a\u53ef\u91cd\u590d\u8c03\u7528\u7684\u5c0f\u5de5\u5177\u3002<\/p>\n<p>function sayHello(): void {<br \/>\n  console.info(&#039;\u4f60\u597d&#xff0c;ArkTS&#xff01;&#039;);<br \/>\n}<\/p>\n<p>\u8c03\u7528\u51fd\u6570&#xff1a;<\/p>\n<p>sayHello();<\/p>\n<h3>12.1 \u5e26\u53c2\u6570\u7684\u51fd\u6570<\/h3>\n<p>function greet(name: string): string {<br \/>\n  return &#096;\u4f60\u597d&#xff0c;${name}&#xff01;&#096;;<br \/>\n}<\/p>\n<p>let message: string &#061; greet(&#039;\u5c0f\u660e&#039;);<br \/>\nconsole.info(message);<\/p>\n<p>\u8fd9\u91cc&#xff1a;<br \/>\n\u2022 name: string \u662f\u8f93\u5165\u53c2\u6570\u3002<br \/>\n\u2022 : string \u662f\u51fd\u6570\u8fd4\u56de\u503c\u7684\u7c7b\u578b\u3002<br \/>\n\u2022 return \u8868\u793a\u628a\u7ed3\u679c\u4ea4\u8fd8\u7ed9\u8c03\u7528\u8005\u3002<\/p>\n<h3>12.2 \u6ca1\u6709\u8fd4\u56de\u503c&#xff1a;void<\/h3>\n<p>function printWelcome(): void {<br \/>\n  console.info(&#039;\u6b22\u8fce\u5f00\u59cb\u5b66\u4e60&#039;);<br \/>\n}<\/p>\n<p>void \u8868\u793a\u8be5\u51fd\u6570\u53ea\u505a\u4e8b\u60c5&#xff0c;\u4e0d\u8fd4\u56de\u53ef\u4f9b\u4fdd\u5b58\u7684\u7ed3\u679c\u3002<\/p>\n<h3>12.3 \u591a\u4e2a\u53c2\u6570<\/h3>\n<p>function add(left: number, right: number): number {<br \/>\n  return left &#043; right;<br \/>\n}<\/p>\n<p>let sum: number &#061; add(3, 5);<\/p>\n<h3>12.4 \u9ed8\u8ba4\u53c2\u6570<\/h3>\n<p>function createTitle(text: string, prefix: string &#061; &#039;\u8bfe\u7a0b&#xff1a;&#039;): string {<br \/>\n  return &#096;${prefix}${text}&#096;;<br \/>\n}<\/p>\n<p>console.info(createTitle(&#039;ArkTS \u5165\u95e8&#039;));<br \/>\nconsole.info(createTitle(&#039;ArkUI \u5e03\u5c40&#039;, &#039;\u7ae0\u8282&#xff1a;&#039;));<\/p>\n<h3>12.5 \u7bad\u5934\u51fd\u6570<\/h3>\n<p>\u7bad\u5934\u51fd\u6570\u5e38\u7528\u4e8e\u6309\u94ae\u70b9\u51fb\u3001\u6570\u7ec4\u5904\u7406\u7b49\u573a\u666f&#xff1a;<\/p>\n<p>let multiply &#061; (left: number, right: number): number &#061;&gt; {<br \/>\n  return left * right;<br \/>\n};<\/p>\n<p>console.info(multiply(2, 3));<\/p>\n<p>\u5f53\u53ea\u6709\u4e00\u884c\u8fd4\u56de\u503c\u65f6\u53ef\u4ee5\u7b80\u5199&#xff1a;<\/p>\n<p>let square &#061; (value: number): number &#061;&gt; value * value;<br \/>\nArkUI \u4e2d\u4f60\u4f1a\u7ecf\u5e38\u89c1\u5230&#xff1a;<br \/>\nButton(&#039;\u70b9\u51fb&#039;)<br \/>\n  .onClick(() &#061;&gt; {<br \/>\n    console.info(&#039;\u6309\u94ae\u88ab\u70b9\u51fb&#039;);<br \/>\n  })<\/p>\n<p>\u8fd9\u4e2a () &#061;&gt; {} \u5c31\u662f\u201c\u70b9\u51fb\u53d1\u751f\u65f6\u518d\u6267\u884c\u7684\u51fd\u6570\u201d\u3002<\/p>\n<h2>13. \u7c7b&#xff1a;\u628a\u6570\u636e\u548c\u884c\u4e3a\u653e\u5728\u4e00\u8d77<\/h2>\n<p>\u7c7b\u9002\u5408\u63cf\u8ff0\u201c\u6709\u72b6\u6001\u3001\u6709\u884c\u4e3a\u201d\u7684\u5bf9\u8c61\u3002<\/p>\n<p>class Counter {<br \/>\n  private value: number &#061; 0;<\/p>\n<p>  increase(): void {<br \/>\n    this.value&#043;&#043;;<br \/>\n  }<\/p>\n<p>  getValue(): number {<br \/>\n    return this.value;<br \/>\n  }<br \/>\n}<\/p>\n<p>let counter: Counter &#061; new Counter();<br \/>\ncounter.increase();<br \/>\nconsole.info(counter.getValue()); \/\/ 1<\/p>\n<p>\u7406\u89e3\u5173\u952e\u5b57&#xff1a;<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260920115013-6aafc8758f4d7.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><br \/>\n\u521d\u5b66\u9636\u6bb5\u53ef\u4ee5\u4f18\u5148\u638c\u63e1 interface \u548c\u51fd\u6570&#xff1b;\u5f53\u4e1a\u52a1\u5bf9\u8c61\u786e\u5b9e\u9700\u8981\u5c01\u88c5\u65b9\u6cd5\u4e0e\u5185\u90e8\u72b6\u6001\u65f6&#xff0c;\u518d\u4f7f\u7528\u7c7b\u3002<\/p>\n<h2>14. \u679a\u4e3e&#xff1a;\u7ed9\u6709\u9650\u9009\u9879\u53d6\u540d\u5b57<\/h2>\n<p>\u4f8b\u5982\u4efb\u52a1\u72b6\u6001\u53ea\u6709\u4e09\u79cd&#xff0c;\u4e0e\u5176\u5230\u5904\u5199\u6570\u5b57&#xff0c;\u4e0d\u5982\u4f7f\u7528\u679a\u4e3e&#xff1a;<\/p>\n<p>enum TaskStatus {<br \/>\n  Todo,<br \/>\n  Doing,<br \/>\n  Done<br \/>\n}<\/p>\n<p>let status: TaskStatus &#061; TaskStatus.Doing;<\/p>\n<p>if (status &#061;&#061;&#061; TaskStatus.Doing) {<br \/>\n  console.info(&#039;\u4efb\u52a1\u6b63\u5728\u8fdb\u884c&#039;);<br \/>\n}<\/p>\n<p>\u679a\u4e3e\u8ba9\u4ee3\u7801\u66f4\u5bb9\u6613\u8bfb&#xff1a;<\/p>\n<p>\/\/ \u4e0d\u591f\u76f4\u89c2<br \/>\nlet state: number &#061; 1;<\/p>\n<p>\/\/ \u66f4\u76f4\u89c2<br \/>\nlet state: TaskStatus &#061; TaskStatus.Doing;<\/p>\n<h2>15. \u8054\u5408\u7c7b\u578b\u3001\u7c7b\u578b\u522b\u540d\u4e0e\u7c7b\u578b\u5b88\u536b<\/h2>\n<h3>15.1 \u8054\u5408\u7c7b\u578b<\/h3>\n<p>\u4e00\u4e2a\u503c\u6709\u65f6\u53ef\u4ee5\u662f\u591a\u79cd\u7c7b\u578b\u4e4b\u4e00&#xff1a;<\/p>\n<p>let orderId: number | string &#061; 1001;<br \/>\norderId &#061; &#039;A-1002&#039;;<\/p>\n<p>\u4f46\u4f7f\u7528\u524d\u8981\u5148\u5224\u65ad\u771f\u5b9e\u7c7b\u578b&#xff1a;<\/p>\n<p>function formatOrderId(id: number | string): string {<br \/>\n  if (typeof id &#061;&#061;&#061; &#039;number&#039;) {<br \/>\n    return &#096;\u6570\u5b57\u8ba2\u5355&#xff1a;${id}&#096;;<br \/>\n  }<br \/>\n  return &#096;\u6587\u672c\u8ba2\u5355&#xff1a;${id.toUpperCase()}&#096;;<br \/>\n}<\/p>\n<p>\u8fd9\u91cc\u7684 typeof \u5224\u65ad\u53eb\u505a\u4e00\u79cd\u7c7b\u578b\u5b88\u536b&#xff1a;\u5b83\u5e2e\u52a9\u7f16\u8bd1\u5668\u786e\u8ba4\u67d0\u6bb5\u4ee3\u7801\u4e2d\u7684\u5b9e\u9645\u7c7b\u578b\u3002<\/p>\n<h3>15.2 \u7c7b\u578b\u522b\u540d type<\/h3>\n<p>\u5982\u679c\u4e00\u6bb5\u7c7b\u578b\u5b9a\u4e49\u6bd4\u8f83\u957f&#xff0c;\u53ef\u4ee5\u53d6\u4e00\u4e2a\u540d\u5b57&#xff1a;<\/p>\n<p>type CourseLevel &#061; &#039;\u521d\u7ea7&#039; | &#039;\u4e2d\u7ea7&#039; | &#039;\u9ad8\u7ea7&#039;;<\/p>\n<p>let level: CourseLevel &#061; &#039;\u521d\u7ea7&#039;;<\/p>\n<p>\u8fd9\u80fd\u9650\u5236\u503c\u53ea\u80fd\u662f\u4e09\u4e2a\u6307\u5b9a\u6587\u672c\u4e4b\u4e00\u3002<\/p>\n<h2>16. \u5f02\u5e38\u5904\u7406&#xff1a;\u9884\u6599\u5931\u8d25&#xff0c;\u800c\u4e0d\u662f\u5bb3\u6015\u5931\u8d25<\/h2>\n<p>\u7a0b\u5e8f\u53ef\u80fd\u9047\u5230\u7f51\u7edc\u5931\u8d25\u3001\u6570\u636e\u683c\u5f0f\u4e0d\u5bf9\u3001\u6743\u9650\u4e0d\u8db3\u7b49\u95ee\u9898\u3002\u5bf9\u53ef\u80fd\u629b\u51fa\u5f02\u5e38\u7684\u903b\u8f91&#xff0c;\u53ef\u4ee5\u4f7f\u7528 try \/ catch&#xff1a;<\/p>\n<p>function parseScore(text: string): number {<br \/>\n  let result: number &#061; Number(text);<\/p>\n<p>  if (Number.isNaN(result)) {<br \/>\n    throw new Error(&#039;\u5206\u6570\u4e0d\u662f\u6709\u6548\u6570\u5b57&#039;);<br \/>\n  }<\/p>\n<p>  return result;<br \/>\n}<\/p>\n<p>try {<br \/>\n  let score: number &#061; parseScore(&#039;90&#039;);<br \/>\n  console.info(&#096;\u5206\u6570\u4e3a&#xff1a;${score}&#096;);<br \/>\n} catch (error) {<br \/>\n  console.error(&#096;\u5904\u7406\u5931\u8d25&#xff1a;${String(error)}&#096;);<br \/>\n}<\/p>\n<p>\u521d\u5b66\u65f6\u5148\u8bb0\u4f4f\u8fd9\u4e2a\u6a21\u5f0f&#xff1a;<\/p>\n<p>try {<br \/>\n  \/\/ \u53ef\u80fd\u5931\u8d25\u7684\u4ee3\u7801<br \/>\n} catch (error) {<br \/>\n  \/\/ \u5931\u8d25\u540e\u7684\u5904\u7406<br \/>\n}<\/p>\n<p>\u4e0d\u8981\u4e3a\u4e86\u201c\u770b\u8d77\u6765\u5b89\u5168\u201d\u800c\u541e\u6389\u9519\u8bef\u3002\u81f3\u5c11\u5e94\u8bb0\u5f55\u9519\u8bef\u6216\u7ed9\u7528\u6237\u4e00\u4e2a\u660e\u786e\u63d0\u793a\u3002<\/p>\n<h2>17. \u5f02\u6b65\u7f16\u7a0b&#xff1a;\u7b49\u5f85\u8017\u65f6\u64cd\u4f5c\u5b8c\u6210<\/h2>\n<p>\u7f51\u7edc\u8bf7\u6c42\u3001\u6587\u4ef6\u8bfb\u5199\u3001\u6570\u636e\u5e93\u64cd\u4f5c\u901a\u5e38\u4e0d\u4f1a\u77ac\u95f4\u5b8c\u6210\u3002\u5f02\u6b65\u4ee3\u7801\u5141\u8bb8\u7a0b\u5e8f\u7b49\u5f85\u7ed3\u679c&#xff0c;\u800c\u4e0d\u628a\u9875\u9762\u5b8c\u5168\u5361\u4f4f\u3002<\/p>\n<h3>17.1 Promise<\/h3>\n<p>Promise \u53ef\u4ee5\u7406\u89e3\u4e3a\u201c\u672a\u6765\u4f1a\u62ff\u5230\u4e00\u4e2a T \u7c7b\u578b\u7684\u7ed3\u679c\u201d\u3002<\/p>\n<p>function getCourseName(): Promise&lt;string&gt; {<br \/>\n  return Promise.resolve(&#039;ArkTS \u96f6\u57fa\u7840\u8bfe\u7a0b&#039;);<br \/>\n}<\/p>\n<h3>17.2 async \/ await<\/h3>\n<p>\u63a8\u8350\u7684\u5f02\u6b65\u5199\u6cd5&#xff1a;<\/p>\n<p>async function loadCourse(): Promise&lt;void&gt; {<br \/>\n  let courseName: string &#061; await getCourseName();<br \/>\n  console.info(courseName);<br \/>\n}<\/p>\n<p>\u542b\u4e49\u662f&#xff1a;<\/p>\n<li>getCourseName() \u5f00\u59cb\u83b7\u53d6\u6570\u636e\u3002<\/li>\n<li>await \u7b49\u5f85\u5b83\u5b8c\u6210\u3002<\/li>\n<li>\u5f97\u5230\u6587\u672c\u540e&#xff0c;\u8d4b\u503c\u7ed9 courseName\u3002<\/li>\n<li>\u7ee7\u7eed\u6267\u884c\u540e\u9762\u7684\u4ee3\u7801\u3002<br \/>\n\u5728 ArkUI \u4e2d&#xff0c;\u5e38\u89c1\u5199\u6cd5\u5982\u4e0b&#xff1a;<\/li>\n<p>async function loadMessage(): Promise&lt;string&gt; {<br \/>\n  return Promise.resolve(&#039;\u5f02\u6b65\u6570\u636e\u52a0\u8f7d\u5b8c\u6210&#039;);<br \/>\n}<\/p>\n<p>&#064;Entry<br \/>\n&#064;Component<br \/>\nstruct AsyncExample {<br \/>\n  &#064;State message: string &#061; &#039;\u5c1a\u672a\u52a0\u8f7d&#039;<\/p>\n<p>  build() {<br \/>\n    Column() {<br \/>\n      Text(this.message)<\/p>\n<p>      Button(&#039;\u52a0\u8f7d\u6570\u636e&#039;)<br \/>\n        .onClick(async () &#061;&gt; {<br \/>\n          this.message &#061; &#039;\u52a0\u8f7d\u4e2d&#8230;&#039;;<br \/>\n          this.message &#061; await loadMessage();<br \/>\n        })<br \/>\n    }<br \/>\n  }<br \/>\n}<\/p>\n<p>\u63d0\u793a&#xff1a;\u771f\u5b9e\u9879\u76ee\u4e2d\u4f1a\u628a\u7f51\u7edc\u8bf7\u6c42\u3001\u9519\u8bef\u5904\u7406\u3001\u52a0\u8f7d\u72b6\u6001\u548c\u7a7a\u6570\u636e\u72b6\u6001\u90fd\u8003\u8651\u8fdb\u53bb&#xff1b;\u5b66\u4e60\u9636\u6bb5\u5148\u638c\u63e1 async\u3001await \u548c Promise \u7684\u5173\u7cfb\u5373\u53ef\u3002<\/p>\n<h2>18. ArkUI \u57fa\u7840\u5e03\u5c40&#xff1a;\u9875\u9762\u5982\u4f55\u6446\u653e<\/h2>\n<p>\u6700\u5e38\u7528\u7684\u5bb9\u5668\u6709&#xff1a;<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260920115013-6aafc875b2e16.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h3>18.1 Column<\/h3>\n<p>Column({ space: 12 }) {<br \/>\n  Text(&#039;\u6807\u9898&#039;)<br \/>\n  Text(&#039;\u5185\u5bb9&#039;)<br \/>\n  Button(&#039;\u786e\u8ba4&#039;)<br \/>\n}<br \/>\n.width(&#039;100%&#039;)<br \/>\n.padding(16)<\/p>\n<h3>18.2 Row<\/h3>\n<p>Row({ space: 8 }) {<br \/>\n  Text(&#039;\u7528\u6237\u540d&#xff1a;&#039;)<br \/>\n  Text(&#039;\u5c0f\u660e&#039;)<br \/>\n}<br \/>\n.width(&#039;100%&#039;)<\/p>\n<h3>18.3 Stack<\/h3>\n<p>\u540e\u5199\u7684\u7ec4\u4ef6\u4f1a\u8986\u76d6\u5728\u5148\u5199\u7684\u7ec4\u4ef6\u4e0a\u65b9&#xff1a;<\/p>\n<p>Stack({ alignContent: Alignment.BottomStart }) {<br \/>\n  Image($r(&#039;app.media.app_icon&#039;))<br \/>\n    .width(120)<br \/>\n    .height(120)<\/p>\n<p>  Text(&#039;\u63a8\u8350&#039;)<br \/>\n    .fontColor(Color.White)<br \/>\n    .backgroundColor(Color.Red)<br \/>\n    .padding(6)<br \/>\n}<\/p>\n<p>\u5982\u679c\u4f60\u7684\u9879\u76ee\u4e2d\u6ca1\u6709\u5bf9\u5e94\u56fe\u7247\u8d44\u6e90&#xff0c;\u53ef\u5148\u4e0d\u8fd0\u884c\u8fd9\u6bb5\u56fe\u7247\u793a\u4f8b&#xff1b;Column\u3001Row \u548c Text \u4e0d\u4f9d\u8d56\u989d\u5916\u8d44\u6e90&#xff0c;\u53ef\u4ee5\u76f4\u63a5\u8fd0\u884c\u3002<\/p>\n<h2>19. \u6837\u5f0f\u94fe\u5f0f\u8c03\u7528&#xff1a;\u7ec4\u4ef6\u540e\u9762\u7684\u70b9\u53f7\u5728\u505a\u4ec0\u4e48<\/h2>\n<p>\u89c2\u5bdf\u4e0b\u9762\u4ee3\u7801&#xff1a;<\/p>\n<p>Text(&#039;ArkTS&#039;)<br \/>\n  .fontSize(24)<br \/>\n  .fontWeight(FontWeight.Bold)<br \/>\n  .fontColor(Color.Blue)<br \/>\n  .margin({ bottom: 12 })<\/p>\n<p>\u5b83\u8868\u793a\u201c\u521b\u5efa\u4e00\u4e2a\u6587\u672c\u201d&#xff0c;\u7136\u540e\u8fde\u7eed\u8bbe\u7f6e\u5b83\u7684\u6837\u5f0f\u3002<br \/>\n\u5e38\u7528\u6837\u5f0f&#xff1a;<\/p>\n<p>Text(&#039;\u793a\u4f8b\u6587\u672c&#039;)<br \/>\n  .fontSize(18)<br \/>\n  .fontColor(&#039;#333333&#039;)<br \/>\n  .fontWeight(FontWeight.Medium)<br \/>\n  .textAlign(TextAlign.Center)<br \/>\n  .width(&#039;100%&#039;)<br \/>\n  .padding(12)<br \/>\n  .backgroundColor(&#039;#F1F3F5&#039;)<br \/>\n  .borderRadius(8)<\/p>\n<p>\u5e38\u7528\u5c3a\u5bf8\u5355\u4f4d&#xff1a;<br \/>\n\u2022 24&#xff1a;\u901a\u5e38\u8868\u793a vp&#xff08;\u865a\u62df\u50cf\u7d20&#xff09;&#xff0c;\u9002\u5408\u5e03\u5c40\u5c3a\u5bf8\u3002<br \/>\n\u2022 \u2018100%\u2019&#xff1a;\u76f8\u5bf9\u7236\u7ec4\u4ef6\u5bbd\u5ea6\u6216\u9ad8\u5ea6\u3002<br \/>\n\u2022 12&#xff1a;\u53ef\u7528\u4e8e padding\u3001margin\u3001fontSize \u7b49\u5e38\u7528\u5c5e\u6027\u3002<br \/>\n\u521d\u5b66\u65f6\u4e0d\u5fc5\u628a\u6240\u6709\u5c5e\u6027\u6b7b\u8bb0\u786c\u80cc\u3002\u5148\u4f1a\u67e5\u7ec4\u4ef6\u7684\u5c5e\u6027\u63d0\u793a&#xff0c;\u5e76\u9010\u6b65\u79ef\u7d2f\u3002<\/p>\n<h2>20. &#064;State&#xff1a;\u9875\u9762\u4e3a\u4ec0\u4e48\u4f1a\u81ea\u52a8\u5237\u65b0<\/h2>\n<p>&#064;State \u662f ArkUI \u6700\u91cd\u8981\u7684\u5165\u95e8\u6982\u5ff5\u4e4b\u4e00\u3002<br \/>\n&#064;Entry<br \/>\n&#064;Component<br \/>\nstruct StateExample {<br \/>\n  &#064;State count: number &#061; 0<\/p>\n<p>  build() {<br \/>\n    Column({ space: 12 }) {<br \/>\n      Text(&#096;\u5f53\u524d\u8ba1\u6570&#xff1a;${this.count}&#096;)<br \/>\n        .fontSize(24)<\/p>\n<p>      Button(&#039;&#043;1&#039;)<br \/>\n        .onClick(() &#061;&gt; {<br \/>\n          this.count&#043;&#043;;<br \/>\n        })<br \/>\n    }<br \/>\n  }<br \/>\n}<\/p>\n<p>\u70b9\u51fb\u6309\u94ae\u540e&#xff0c;count \u53d8\u5316&#xff0c;\u9875\u9762\u4e2d\u7684 Text \u4f1a\u81ea\u52a8\u663e\u793a\u65b0\u503c\u3002<br \/>\n\u53ef\u4ee5\u8fd9\u6837\u7406\u89e3&#xff1a;<\/p>\n<p>&#064;State \u6570\u636e\u53d8\u5316<br \/>\n        \u2193<br \/>\nArkUI \u53d1\u73b0\u8fd9\u4e2a\u6570\u636e\u88ab\u9875\u9762\u4f7f\u7528<br \/>\n        \u2193<br \/>\n\u76f8\u5173 UI \u81ea\u52a8\u91cd\u65b0\u8ba1\u7b97\u5e76\u5237\u65b0<\/p>\n<h3>20.1 \u666e\u901a\u53d8\u91cf\u4e0e &#064;State \u7684\u5dee\u522b<\/h3>\n<p>&#064;Component<br \/>\nstruct WrongExample {<br \/>\ncount: number &#061; 0 \/\/ \u666e\u901a\u5b57\u6bb5&#xff0c;\u4e0d\u9002\u5408\u4f5c\u4e3a\u9700\u8981\u9a71\u52a8 UI \u5237\u65b0\u7684\u9875\u9762\u72b6\u6001<\/p>\n<p>build() {<br \/>\n  Column() {<br \/>\n    Text(&#096;${this.count}&#096;)<br \/>\n    Button(&#039;&#043;1&#039;).onClick(() &#061;&gt; {<br \/>\n      this.count&#043;&#043;;<br \/>\n    })<br \/>\n  }<br \/>\n}<br \/>\n}<\/p>\n<p>\u5bf9\u4e8e\u201c\u7528\u6237\u70b9\u51fb\u540e\u8981\u7acb\u5373\u53cd\u6620\u5230\u754c\u9762\u4e0a\u201d\u7684\u6570\u636e&#xff0c;\u5e94\u4f7f\u7528 &#064;State&#xff1a;<\/p>\n<p>&#064;State count: number &#061; 0<\/p>\n<h3>20.2 \u72b6\u6001\u8bbe\u8ba1\u7684\u5c0f\u539f\u5219<\/h3>\n<p>\u9002\u5408 &#064;State \u7684\u6570\u636e&#xff1a;<br \/>\n\u2022 \u8f93\u5165\u6846\u4e2d\u6b63\u5728\u8f93\u5165\u7684\u6587\u5b57\u3002<br \/>\n\u2022 \u5f53\u524d\u9009\u4e2d\u7684\u6807\u7b7e\u3002<br \/>\n\u2022 \u5217\u8868\u4e2d\u7684\u4efb\u52a1\u6570\u636e\u3002<br \/>\n\u2022 \u52a0\u8f7d\u4e2d\u3001\u52a0\u8f7d\u6210\u529f\u3001\u52a0\u8f7d\u5931\u8d25\u7684\u9875\u9762\u72b6\u6001\u3002<br \/>\n\u2022 \u5f53\u524d\u8ba1\u6570\u3001\u5f53\u524d\u9875\u7801\u3002<br \/>\n\u4e0d\u9002\u5408\u628a\u6240\u6709\u6570\u636e\u90fd\u65e0\u8111\u653e\u8fdb &#064;State\u3002\u4f8b\u5982\u4e0d\u4f1a\u5f71\u54cd\u5f53\u524d\u9875\u9762\u5c55\u793a\u7684\u5e38\u91cf\u3001\u5de5\u5177\u5bf9\u8c61\u3001\u4e00\u6b21\u6027\u4e34\u65f6\u8ba1\u7b97\u7ed3\u679c&#xff0c;\u901a\u5e38\u4e0d\u9700\u8981\u9875\u9762\u72b6\u6001\u88c5\u9970\u3002<\/p>\n<h2>21. \u7ec4\u4ef6\u901a\u4fe1&#xff1a;\u7236\u7ec4\u4ef6\u628a\u6570\u636e\u4ea4\u7ed9\u5b50\u7ec4\u4ef6<\/h2>\n<h3>21.1 &#064;Prop&#xff1a;\u7236\u4f20\u5b50&#xff0c;\u5b50\u7ec4\u4ef6\u53ea\u8bfb\u4f7f\u7528<\/h3>\n<p>&#064;Component<br \/>\nstruct UserGreeting {<br \/>\n  &#064;Prop name: string &#061; &#039;\u8bbf\u5ba2&#039;<\/p>\n<p>  build() {<br \/>\n    Text(&#096;\u4f60\u597d&#xff0c;${this.name}&#096;)<br \/>\n  }<br \/>\n}<\/p>\n<p>&#064;Entry<br \/>\n&#064;Component<br \/>\nstruct ParentPage {<br \/>\n  build() {<br \/>\n    Column() {<br \/>\n      UserGreeting({ name: &#039;\u5c0f\u660e&#039; })<br \/>\n      UserGreeting({ name: &#039;\u5c0f\u7ea2&#039; })<br \/>\n    }<br \/>\n  }<br \/>\n}<\/p>\n<p>\u7236\u7ec4\u4ef6\u4f7f\u7528\u5b50\u7ec4\u4ef6\u65f6\u50cf\u4f20\u53c2\u6570\u4e00\u6837\u4f20\u5165&#xff1a;<\/p>\n<p>UserGreeting({ name: &#039;\u5c0f\u660e&#039; })<\/p>\n<h3>21.2 &#064;Link&#xff1a;\u7236\u5b50\u5171\u4eab\u53ef\u4fee\u6539\u72b6\u6001<\/h3>\n<p>\u5f53\u5b50\u7ec4\u4ef6\u65e2\u8981\u5c55\u793a\u6570\u636e&#xff0c;\u53c8\u8981\u4fee\u6539\u7236\u7ec4\u4ef6\u7684\u72b6\u6001&#xff0c;\u53ef\u4ee5\u4f7f\u7528<\/p>\n<p>&#064;Link&#xff1a;<br \/>\n&#064;Component<br \/>\nstruct CounterButton {<br \/>\n  &#064;Link count: number<\/p>\n<p>  build() {<br \/>\n    Button(&#096;\u5b50\u7ec4\u4ef6\u52a0 1&#xff1a;${this.count}&#096;)<br \/>\n      .onClick(() &#061;&gt; {<br \/>\n        this.count&#043;&#043;;<br \/>\n      })<br \/>\n  }<br \/>\n}<\/p>\n<p>&#064;Entry<br \/>\n&#064;Component<br \/>\nstruct ParentCounterPage {<br \/>\n  &#064;State count: number &#061; 0<\/p>\n<p>  build() {<br \/>\n    Column({ space: 12 }) {<br \/>\n      Text(&#096;\u7236\u7ec4\u4ef6\u8ba1\u6570&#xff1a;${this.count}&#096;)<br \/>\n        .fontSize(24)<\/p>\n<p>      CounterButton({ count: $count })<br \/>\n    }<br \/>\n    .padding(24)<br \/>\n  }<br \/>\n}<\/p>\n<p>\u6ce8\u610f\u4f20\u5165\u65f6\u662f $count&#xff0c;\u4e0d\u662f count&#xff1a;<\/p>\n<p>CounterButton({ count: $count })<\/p>\n<p>\u521d\u5b66\u8bb0\u5fc6&#xff1a;<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260920115013-6aafc875d7739.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h2>22. \u9875\u9762\u6e32\u67d3\u8bed\u6cd5&#xff1a;\u6761\u4ef6\u663e\u793a\u548c\u5faa\u73af\u663e\u793a<\/h2>\n<h3>22.1 if&#xff1a;\u6709\u6761\u4ef6\u5730\u663e\u793a\u7ec4\u4ef6<\/h3>\n<p>&#064;Entry<br \/>\n&#064;Component<br \/>\nstruct LoginPage {<br \/>\n  &#064;State isLogin: boolean &#061; false<\/p>\n<p>  build() {<br \/>\n    Column({ space: 12 }) {<br \/>\n      if (this.isLogin) {<br \/>\n        Text(&#039;\u6b22\u8fce\u56de\u6765&#xff01;&#039;)<br \/>\n          .fontSize(24)<br \/>\n      } else {<br \/>\n        Text(&#039;\u8bf7\u5148\u767b\u5f55&#039;)<br \/>\n          .fontSize(24)<br \/>\n      }<\/p>\n<p>      Button(this.isLogin ? &#039;\u9000\u51fa\u767b\u5f55&#039; : &#039;\u767b\u5f55&#039;)<br \/>\n        .onClick(() &#061;&gt; {<br \/>\n          this.isLogin &#061; !this.isLogin;<br \/>\n        })<br \/>\n    }<br \/>\n    .padding(24)<br \/>\n  }<br \/>\n}<\/p>\n<p>\u8fd9\u91cc if \u4e0d\u662f\u666e\u901a\u51fd\u6570\u4e2d\u7684\u6761\u4ef6&#xff0c;\u800c\u662f\u5728 build() \u4e2d\u51b3\u5b9a\u201c\u663e\u793a\u54ea\u4e00\u7ec4 UI\u201d\u3002<\/p>\n<h3>22.2 ForEach&#xff1a;\u628a\u6570\u7ec4\u753b\u6210\u5217\u8868<\/h3>\n<p>&#064;Entry<br \/>\n&#064;Component<br \/>\nstruct FruitPage {<br \/>\n  &#064;State fruits: string[] &#061; [&#039;\u82f9\u679c&#039;, &#039;\u9999\u8549&#039;, &#039;\u6a59\u5b50&#039;]<\/p>\n<p>  build() {<br \/>\n    Column({ space: 8 }) {<br \/>\n      ForEach(this.fruits, (fruit: string) &#061;&gt; {<br \/>\n        Text(fruit)<br \/>\n          .fontSize(20)<br \/>\n          .width(&#039;100%&#039;)<br \/>\n          .padding(12)<br \/>\n          .backgroundColor(&#039;#F1F3F5&#039;)<br \/>\n          .borderRadius(8)<br \/>\n      }, (fruit: string) &#061;&gt; fruit)<br \/>\n    }<br \/>\n    .padding(16)<br \/>\n  }<br \/>\n}<\/p>\n<p>ForEach \u7684\u4e09\u4e2a\u90e8\u5206&#xff1a;<\/p>\n<p>ForEach(<br \/>\n  \u6570\u636e\u6570\u7ec4,<br \/>\n  \u6bcf\u4e00\u9879\u5982\u4f55\u7ed8\u5236,<br \/>\n  \u6bcf\u4e00\u9879\u7684\u552f\u4e00\u6807\u8bc6<br \/>\n)<\/p>\n<p>\u6700\u540e\u7684\u552f\u4e00\u6807\u8bc6\u5f88\u91cd\u8981\u3002\u771f\u5b9e\u5217\u8868\u4e2d\u5efa\u8bae\u4f7f\u7528\u7a33\u5b9a\u7684 id&#xff0c;\u4e0d\u8981\u53ea\u4f9d\u8d56\u5bb9\u6613\u91cd\u590d\u6216\u53d8\u5316\u7684\u6587\u672c\u3002<\/p>\n<h2>23. \u8f93\u5165\u4e0e\u4e8b\u4ef6&#xff1a;\u8ba9\u7528\u6237\u548c\u9875\u9762\u4e92\u52a8<\/h2>\n<h3>23.1 TextInput<\/h3>\n<p>&#064;Entry<br \/>\n&#064;Component<br \/>\nstruct InputPage {<br \/>\n  &#064;State inputText: string &#061; &#039;&#039;<\/p>\n<p>  build() {<br \/>\n    Column({ space: 12 }) {<br \/>\n      TextInput({ placeholder: &#039;\u8bf7\u8f93\u5165\u4f60\u7684\u540d\u5b57&#039;, text: this.inputText })<br \/>\n        .onChange((value: string) &#061;&gt; {<br \/>\n          this.inputText &#061; value;<br \/>\n        })<\/p>\n<p>      Text(this.inputText.length &gt; 0 ? &#096;\u4f60\u597d&#xff0c;${this.inputText}&#096; : &#039;\u8fd8\u6ca1\u6709\u8f93\u5165\u5185\u5bb9&#039;)<br \/>\n    }<br \/>\n    .padding(24)<br \/>\n  }<br \/>\n}<\/p>\n<p>\u6838\u5fc3\u5173\u7cfb&#xff1a;<\/p>\n<p>\u8f93\u5165\u6846\u5185\u5bb9\u53d8\u5316<br \/>\n      \u2193<br \/>\nonChange \u63a5\u6536\u5230 value<br \/>\n      \u2193<br \/>\n\u66f4\u65b0 &#064;State inputText<br \/>\n      \u2193<br \/>\nText \u4f7f\u7528\u65b0\u503c\u91cd\u65b0\u663e\u793a<\/p>\n<h3>23.2 \u5e38\u7528\u4e8b\u4ef6<\/h3>\n<p>Button(&#039;\u70b9\u51fb&#039;)<br \/>\n  .onClick(() &#061;&gt; {<br \/>\n    console.info(&#039;\u70b9\u51fb\u4e8b\u4ef6&#039;);<br \/>\n  });<\/p>\n<p>TextInput({ placeholder: &#039;\u8f93\u5165\u5185\u5bb9&#039; })<br \/>\n  .onChange((value: string) &#061;&gt; {<br \/>\n    console.info(&#096;\u8f93\u5165\u5185\u5bb9&#xff1a;${value}&#096;);<br \/>\n  });<\/p>\n<p>\u4e8b\u4ef6\u51fd\u6570\u4e0d\u8981\u5199\u6210\u7acb\u5373\u6267\u884c&#xff1a;<\/p>\n<p>\/\/ \u9519\u8bef\u793a\u610f&#xff1a;\u4e0d\u8981\u8fd9\u6837\u5199<br \/>\n\/\/ .onClick(this.doSomething())<\/p>\n<p>\u5e94\u8be5\u4f20\u5165\u4e00\u4e2a\u51fd\u6570&#xff1a;<\/p>\n<p>.onClick(() &#061;&gt; {<br \/>\n  this.doSomething();<br \/>\n})<\/p>\n<h2>24. \u8d44\u6e90\u5f15\u7528&#xff1a;$r() \u662f\u4ec0\u4e48<\/h2>\n<p>HarmonyOS \u9879\u76ee\u4e2d\u7684\u8d44\u6e90\u901a\u5e38\u653e\u5728 resources \u76ee\u5f55\u3002\u5f15\u7528\u5b57\u7b26\u4e32\u3001\u989c\u8272\u3001\u56fe\u7247\u7b49\u8d44\u6e90\u65f6&#xff0c;\u7ecf\u5e38\u4f1a\u770b\u5230 $r()&#xff1a;<\/p>\n<p>Text($r(&#039;app.string.app_name&#039;))<\/p>\n<p>Image($r(&#039;app.media.app_icon&#039;))<\/p>\n<p>\u53ef\u4ee5\u7c97\u7565\u7406\u89e3\u4e3a&#xff1a;<br \/>\n\u201c\u5230\u5e94\u7528\u8d44\u6e90\u6587\u4ef6\u4e2d&#xff0c;\u6309\u8d44\u6e90\u540d\u53d6\u51fa\u5bf9\u5e94\u5185\u5bb9\u3002\u201d<br \/>\n\u521d\u5b66\u9636\u6bb5&#xff0c;\u76f4\u63a5\u4f7f\u7528\u6587\u672c\u548c\u989c\u8272\u5373\u53ef&#xff1a;<\/p>\n<p>Text(&#039;\u6b22\u8fce\u5b66\u4e60 ArkTS&#039;)<br \/>\n  .fontColor(&#039;#0A59F7&#039;)<\/p>\n<p>\u5f53\u9879\u76ee\u9700\u8981\u591a\u8bed\u8a00\u3001\u7edf\u4e00\u4e3b\u9898\u548c\u53ef\u7ef4\u62a4\u56fe\u7247\u8d44\u6e90\u65f6&#xff0c;\u518d\u9010\u6b65\u5b66\u4e60\u8d44\u6e90\u6587\u4ef6\u7684\u7ec4\u7ec7\u65b9\u5f0f\u3002<\/p>\n<h2>25. ArkTS \u521d\u5b66\u8005\u6700\u5e38\u9047\u5230\u7684\u9519\u8bef<\/h2>\n<h3>25.1 \u628a\u6587\u672c\u5fd8\u8bb0\u52a0\u5f15\u53f7<\/h3>\n<p>\/\/ \u9519\u8bef<br \/>\n\/\/ let name: string &#061; \u5c0f\u660e;<\/p>\n<p>\/\/ \u6b63\u786e<br \/>\nlet name: string &#061; &#039;\u5c0f\u660e&#039;;<\/p>\n<h3>25.2 \u628a &#061; \u4e0e &#061;&#061;&#061; \u6df7\u6dc6<\/h3>\n<p>let score: number &#061; 90;<\/p>\n<p>\/\/ \u6b63\u786e&#xff1a;\u6bd4\u8f83<br \/>\nif (score &#061;&#061;&#061; 90) {<br \/>\n  console.info(&#039;\u6ee1\u5206&#039;);<br \/>\n}<\/p>\n<p>\u2022 &#061;&#xff1a;\u8d4b\u503c\u3002<br \/>\n\u2022 &#061;&#061;&#061;&#xff1a;\u6bd4\u8f83\u662f\u5426\u76f8\u7b49\u3002<\/p>\n<h3>25.3 \u5fd8\u8bb0\u4f7f\u7528 this<\/h3>\n<p>\u5728\u7ec4\u4ef6\u5185\u90e8\u8bbf\u95ee\u5b57\u6bb5\u65f6\u901a\u5e38\u8981\u5199 this.&#xff1a;<\/p>\n<p>&#064;State count: number &#061; 0<\/p>\n<p>\/\/ \u6b63\u786e<br \/>\nthis.count&#043;&#043;;<\/p>\n<h3>25.4 \u628a\u4f1a\u6539\u53d8\u9875\u9762\u7684\u53d8\u91cf\u5199\u6210\u666e\u901a\u5b57\u6bb5<\/h3>\n<p>\/\/ \u8981\u8ba9 UI \u81ea\u52a8\u5237\u65b0&#xff0c;\u4f7f\u7528 &#064;State<br \/>\n&#064;State title: string &#061; &#039;\u521d\u59cb\u6807\u9898&#039;;<\/p>\n<h3>25.5 ForEach \u4e2d\u6ca1\u6709\u7a33\u5b9a\u552f\u4e00\u6807\u8bc6<\/h3>\n<p>\u5217\u8868\u6709\u589e\u52a0\u3001\u5220\u9664\u3001\u6392\u5e8f\u7b49\u64cd\u4f5c\u65f6&#xff0c;\u5c3d\u91cf\u4f7f\u7528\u4e1a\u52a1\u552f\u4e00 id&#xff1a;<\/p>\n<p>interface Todo {<br \/>\n  id: number;<br \/>\n  title: string;<br \/>\n}<\/p>\n<p>ForEach(this.todos, (item: Todo) &#061;&gt; {<br \/>\n  Text(item.title)<br \/>\n}, (item: Todo) &#061;&gt; item.id.toString())<\/p>\n<h3>25.6 \u628a\u590d\u6742\u4e1a\u52a1\u5168\u585e\u8fdb build()<\/h3>\n<p>build() \u5e94\u4e3b\u8981\u8d1f\u8d23\u63cf\u8ff0 UI\u3002\u590d\u6742\u8ba1\u7b97\u3001\u6570\u636e\u8f6c\u6362\u3001\u7f51\u7edc\u8c03\u7528\u53ef\u4ee5\u63d0\u53d6\u6210\u51fd\u6570&#xff1a;<\/p>\n<p>private getWelcomeText(): string {<br \/>\n  return this.userName.length &gt; 0 ? &#096;\u4f60\u597d&#xff0c;${this.userName}&#096; : &#039;\u4f60\u597d&#xff0c;\u8bbf\u5ba2&#039;;<br \/>\n}<\/p>\n<p>build() {<br \/>\n  Text(this.getWelcomeText())<br \/>\n}<\/p>\n<h2>26. \u5b8c\u6574\u53ef\u8fd0\u884c\u793a\u4f8b&#xff1a;ArkTS \u8bed\u6cd5\u5b9e\u9a8c\u5ba4<\/h2>\n<p>\u628a\u4e0b\u9762\u5b8c\u6574\u4ee3\u7801\u590d\u5236\u5230 entry\/src\/main\/ets\/pages\/Index.ets&#xff0c;\u66ff\u6362\u539f\u6709\u5185\u5bb9\u540e\u8fd0\u884c\u3002\u70b9\u51fb\u6309\u94ae\u5373\u53ef\u5728\u9875\u9762\u4e0a\u770b\u5230\u53d8\u91cf\u3001\u6570\u7ec4\u3001\u5bf9\u8c61\u3001\u51fd\u6570\u3001\u7c7b\u3001\u679a\u4e3e\u548c\u5f02\u6b65\u8bed\u6cd5\u7684\u6267\u884c\u7ed3\u679c\u3002<\/p>\n<p>enum LearningStatus {<br \/>\n  NotStarted,<br \/>\n  Learning,<br \/>\n  Finished<br \/>\n}<\/p>\n<p>interface Learner {<br \/>\n  name: string;<br \/>\n  age: number;<br \/>\n  courses: string[];<br \/>\n}<\/p>\n<p>class SimpleCounter {<br \/>\n  private value: number &#061; 0;<\/p>\n<p>  increase(): void {<br \/>\n    this.value&#043;&#043;;<br \/>\n  }<\/p>\n<p>  getValue(): number {<br \/>\n    return this.value;<br \/>\n  }<br \/>\n}<\/p>\n<p>function getLevel(score: number): string {<br \/>\n  if (score &gt;&#061; 90) {<br \/>\n    return &#039;\u4f18\u79c0&#039;;<br \/>\n  } else if (score &gt;&#061; 60) {<br \/>\n    return &#039;\u53ca\u683c&#039;;<br \/>\n  }<br \/>\n  return &#039;\u7ee7\u7eed\u52aa\u529b&#039;;<br \/>\n}<\/p>\n<p>function getAsyncMessage(): Promise&lt;string&gt; {<br \/>\n  return Promise.resolve(&#039;\u5f02\u6b65\u4efb\u52a1\u5df2\u5b8c\u6210&#xff1a;\u4f60\u5df2\u7ecf\u638c\u63e1\u4e86 async \/ await \u7684\u57fa\u672c\u5199\u6cd5\u3002&#039;);<br \/>\n}<\/p>\n<p>&#064;Entry<br \/>\n&#064;Component<br \/>\nstruct Index {<br \/>\n  &#064;State resultText: string &#061; &#039;\u70b9\u51fb\u201c\u8fd0\u884c\u793a\u4f8b\u201d&#xff0c;\u5728\u8fd9\u91cc\u67e5\u770b\u8f93\u51fa\u3002&#039;<\/p>\n<p>  build() {<br \/>\n    Column({ space: 16 }) {<br \/>\n      Text(&#039;ArkTS \u8bed\u6cd5\u5b9e\u9a8c\u5ba4&#039;)<br \/>\n        .fontSize(26)<br \/>\n        .fontWeight(FontWeight.Bold)<\/p>\n<p>      Text(this.resultText)<br \/>\n        .fontSize(16)<br \/>\n        .lineHeight(24)<br \/>\n        .width(&#039;100%&#039;)<br \/>\n        .padding(16)<br \/>\n        .backgroundColor(&#039;#F1F3F5&#039;)<br \/>\n        .borderRadius(12)<\/p>\n<p>      Button(&#039;\u8fd0\u884c\u793a\u4f8b&#039;)<br \/>\n        .width(&#039;100%&#039;)<br \/>\n        .onClick(async () &#061;&gt; {<br \/>\n          await this.runDemo();<br \/>\n        })<br \/>\n    }<br \/>\n    .width(&#039;100%&#039;)<br \/>\n    .height(&#039;100%&#039;)<br \/>\n    .padding(24)<br \/>\n    .justifyContent(FlexAlign.Center)<br \/>\n  }<\/p>\n<p>  private async runDemo(): Promise&lt;void&gt; {<br \/>\n    const appName: string &#061; &#039;ArkTS \u5165\u95e8&#039;;<br \/>\n    let score: number &#061; 88;<br \/>\n    const isLearning: boolean &#061; true;<\/p>\n<p>    const learner: Learner &#061; {<br \/>\n      name: &#039;\u5c0f\u660e&#039;,<br \/>\n      age: 18,<br \/>\n      courses: [&#039;\u53d8\u91cf&#039;, &#039;\u51fd\u6570&#039;, &#039;\u7ec4\u4ef6&#039;]<br \/>\n    };<\/p>\n<p>    const counter: SimpleCounter &#061; new SimpleCounter();<br \/>\n    counter.increase();<br \/>\n    counter.increase();<\/p>\n<p>    const status: LearningStatus &#061; LearningStatus.Learning;<br \/>\n    const courseText: string &#061; learner.courses.join(&#039;\u3001&#039;);<br \/>\n    const level: string &#061; getLevel(score);<br \/>\n    const asyncMessage: string &#061; await getAsyncMessage();<\/p>\n<p>    this.resultText &#061;<br \/>\n      &#096;\u8bfe\u7a0b&#xff1a;${appName}\\\\n&#096; &#043;<br \/>\n      &#096;\u5b66\u4e60\u8005&#xff1a;${learner.name}&#xff0c;${learner.age} \u5c81\\\\n&#096; &#043;<br \/>\n      &#096;\u6b63\u5728\u5b66\u4e60&#xff1a;${isLearning ? &#039;\u662f&#039; : &#039;\u5426&#039;}\\\\n&#096; &#043;<br \/>\n      &#096;\u8bfe\u7a0b\u5217\u8868&#xff1a;${courseText}\\\\n&#096; &#043;<br \/>\n      &#096;\u5206\u6570&#xff1a;${score}&#xff0c;\u8bc4\u4ef7&#xff1a;${level}\\\\n&#096; &#043;<br \/>\n      &#096;\u8ba1\u6570\u5668\u503c&#xff1a;${counter.getValue()}\\\\n&#096; &#043;<br \/>\n      &#096;\u5b66\u4e60\u72b6\u6001\u679a\u4e3e\u503c&#xff1a;${status}\\\\n&#096; &#043;<br \/>\n      &#096;${asyncMessage}&#096;;<br \/>\n  }<br \/>\n}<\/p>\n<p>\u4f60\u53ef\u4ee5\u5c1d\u8bd5\u81ea\u5df1\u4fee\u6539&#xff1a;<\/p>\n<li>\u628a score \u6539\u6210 95&#xff0c;\u89c2\u5bdf\u8bc4\u4ef7\u53d8\u5316\u3002<\/li>\n<li>\u5728 courses \u4e2d\u589e\u52a0 \u2018\u5f02\u6b65\u7f16\u7a0b\u2019\u3002<\/li>\n<li>\u591a\u8c03\u7528\u4e00\u6b21 counter.increase()\u3002<\/li>\n<li>\u628a learner.name \u6539\u6210\u4f60\u81ea\u5df1\u7684\u540d\u5b57\u3002<\/li>\n<h2>27 \u4e00\u4efd\u901f\u67e5\u8868<\/h2>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260920115014-6aafc87602a76.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><br \/>\n<img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260920115014-6aafc87638573.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>0.\u5148\u5efa\u7acb\u6b63\u786e\u8ba4\u8bc6&#xff1a;ArkTS\u3001TypeScript \u4e0e ArkUI \u5206\u522b\u662f\u4ec0\u4e48<br \/>\n\u521d\u5b66 HarmonyOS \u65f6&#xff0c;\u6700\u5bb9\u6613\u6df7\u6dc6\u7684\u6709\u4e09\u4e2a\u540d\u8bcd&#xff1a;\u4e00\u53e5\u8bdd\u8bb0\u5fc6&#xff1a;<br \/>\n\u2022 ArkTS \u662f\u5199\u903b\u8f91\u3001\u7c7b\u578b\u548c\u6570\u636e\u7684\u8bed\u8a00\u3002<br \/>\n\u2022 ArkUI \u662f\u7528 ArkTS \u63cf\u8ff0\u754c\u9762\u7684\u65b9\u5f0f\u3002<br \/>\n\u2022 \u4f60\u5728 .ets \u6587\u4ef6\u91cc\u901a\u5e38\u4f1a\u540c\u65f6\u5199\u201c\u6570\u636e\u5904\u7406\u4ee3\u7801\u201d\u548c\u201c\u9875\u9762\u4ee3\u7801\u201d\u3002<br \/>\n\u4f8b\u5982&#xff1a;<br \/>\nlet userName: string  \u5c0f\u660e; \/\/ ArkTS&amp;#xff1a<\/p>\n","protected":false},"author":2,"featured_media":108024,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[280,67],"topic":[],"class_list":["post-108034","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-harmonyos","tag-67"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>HarmonyOS ArkTS \u96f6\u57fa\u7840\u8bed\u6cd5\u8bb2\u4e49\uff1a\u4ece\u7b2c\u4e00\u884c\u4ee3\u7801\u5230\u53ef\u8fd0\u884c\u9875\u9762 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/108034.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"HarmonyOS ArkTS \u96f6\u57fa\u7840\u8bed\u6cd5\u8bb2\u4e49\uff1a\u4ece\u7b2c\u4e00\u884c\u4ee3\u7801\u5230\u53ef\u8fd0\u884c\u9875\u9762 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"0.\u5148\u5efa\u7acb\u6b63\u786e\u8ba4\u8bc6&#xff1a;ArkTS\u3001TypeScript \u4e0e ArkUI \u5206\u522b\u662f\u4ec0\u4e48 \u521d\u5b66 HarmonyOS \u65f6&#xff0c;\u6700\u5bb9\u6613\u6df7\u6dc6\u7684\u6709\u4e09\u4e2a\u540d\u8bcd&#xff1a;\u4e00\u53e5\u8bdd\u8bb0\u5fc6&#xff1a; \u2022 ArkTS \u662f\u5199\u903b\u8f91\u3001\u7c7b\u578b\u548c\u6570\u636e\u7684\u8bed\u8a00\u3002 \u2022 ArkUI \u662f\u7528 ArkTS \u63cf\u8ff0\u754c\u9762\u7684\u65b9\u5f0f\u3002 \u2022 \u4f60\u5728 .ets \u6587\u4ef6\u91cc\u901a\u5e38\u4f1a\u540c\u65f6\u5199\u201c\u6570\u636e\u5904\u7406\u4ee3\u7801\u201d\u548c\u201c\u9875\u9762\u4ee3\u7801\u201d\u3002 \u4f8b\u5982&#xff1a; let userName: string \u5c0f\u660e; \/\/ ArkTS&amp;#xff1a\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/108034.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-20T11:50:15+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260920115012-6aafc874d88c0.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/108034.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/108034.html\",\"name\":\"HarmonyOS ArkTS \u96f6\u57fa\u7840\u8bed\u6cd5\u8bb2\u4e49\uff1a\u4ece\u7b2c\u4e00\u884c\u4ee3\u7801\u5230\u53ef\u8fd0\u884c\u9875\u9762 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-09-20T11:50:15+00:00\",\"dateModified\":\"2026-09-20T11:50:15+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/108034.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/108034.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/108034.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"HarmonyOS ArkTS \u96f6\u57fa\u7840\u8bed\u6cd5\u8bb2\u4e49\uff1a\u4ece\u7b2c\u4e00\u884c\u4ee3\u7801\u5230\u53ef\u8fd0\u884c\u9875\u9762\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"HarmonyOS ArkTS \u96f6\u57fa\u7840\u8bed\u6cd5\u8bb2\u4e49\uff1a\u4ece\u7b2c\u4e00\u884c\u4ee3\u7801\u5230\u53ef\u8fd0\u884c\u9875\u9762 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/108034.html","og_locale":"zh_CN","og_type":"article","og_title":"HarmonyOS ArkTS \u96f6\u57fa\u7840\u8bed\u6cd5\u8bb2\u4e49\uff1a\u4ece\u7b2c\u4e00\u884c\u4ee3\u7801\u5230\u53ef\u8fd0\u884c\u9875\u9762 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"0.\u5148\u5efa\u7acb\u6b63\u786e\u8ba4\u8bc6&#xff1a;ArkTS\u3001TypeScript \u4e0e ArkUI \u5206\u522b\u662f\u4ec0\u4e48 \u521d\u5b66 HarmonyOS \u65f6&#xff0c;\u6700\u5bb9\u6613\u6df7\u6dc6\u7684\u6709\u4e09\u4e2a\u540d\u8bcd&#xff1a;\u4e00\u53e5\u8bdd\u8bb0\u5fc6&#xff1a; \u2022 ArkTS \u662f\u5199\u903b\u8f91\u3001\u7c7b\u578b\u548c\u6570\u636e\u7684\u8bed\u8a00\u3002 \u2022 ArkUI \u662f\u7528 ArkTS \u63cf\u8ff0\u754c\u9762\u7684\u65b9\u5f0f\u3002 \u2022 \u4f60\u5728 .ets \u6587\u4ef6\u91cc\u901a\u5e38\u4f1a\u540c\u65f6\u5199\u201c\u6570\u636e\u5904\u7406\u4ee3\u7801\u201d\u548c\u201c\u9875\u9762\u4ee3\u7801\u201d\u3002 \u4f8b\u5982&#xff1a; let userName: string \u5c0f\u660e; \/\/ ArkTS&amp;#xff1a","og_url":"https:\/\/www.wsisp.com\/helps\/108034.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-09-20T11:50:15+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260920115012-6aafc874d88c0.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"10 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/108034.html","url":"https:\/\/www.wsisp.com\/helps\/108034.html","name":"HarmonyOS ArkTS \u96f6\u57fa\u7840\u8bed\u6cd5\u8bb2\u4e49\uff1a\u4ece\u7b2c\u4e00\u884c\u4ee3\u7801\u5230\u53ef\u8fd0\u884c\u9875\u9762 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-09-20T11:50:15+00:00","dateModified":"2026-09-20T11:50:15+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/108034.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/108034.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/108034.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"HarmonyOS ArkTS \u96f6\u57fa\u7840\u8bed\u6cd5\u8bb2\u4e49\uff1a\u4ece\u7b2c\u4e00\u884c\u4ee3\u7801\u5230\u53ef\u8fd0\u884c\u9875\u9762"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/108034","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=108034"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/108034\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/108024"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=108034"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=108034"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=108034"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=108034"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}