1# 验证代码段检测---需检测
2
3> **说明:**
4>
5> 本文档检测` js、ts、JavaScript、javascript、TypeScript、typescript`代码段
6
7## js代码段
8
9代码段-js:
10
11**示例:**
12
13```js
14// js代码段:
15// xxx.ets
16@Entry
17@Component
18struct GridContainerExample {
19  @State sizeType: SizeType = SizeType.XS
20
21  build() {
22    Column({ space: 5 }) {
23      GridContainer({ columns: 12, sizeType: this.sizeType, gutter: 10, margin: 20 }) {
24        Row() {
25          Text('1')
26            .useSizeType({
27              xs: { span: 6, offset: 0 },
28              sm: { span: 2, offset: 0 },
29              md: { span: 2, offset: 0 },
30              lg: { span: 2, offset: 0 }
31            })
32            .height(50).backgroundColor(0x4682B4).textAlign(TextAlign.Center)
33          Text('2')
34            .useSizeType({
35              xs: { span: 2, offset: 6 },
36              sm: { span: 6, offset: 2 },
37              md: { span: 2, offset: 2 },
38              lg: { span: 2, offset: 2 }
39            })
40            .height(50).backgroundColor(0x00BFFF).textAlign(TextAlign.Center)
41          Text('3')
42            .useSizeType({
43              xs: { span: 2, offset: 8 },
44              sm: { span: 2, offset: 8 },
45              md: { span: 6, offset: 4 },
46              lg: { span: 2, offset: 4 }
47            })
48            .height(50).backgroundColor(0x4682B4).textAlign(TextAlign.Center)
49          Text('4')
50            .useSizeType({
51              xs: { span: 2, offset: 10 },
52              sm: { span: 2, offset: 10 },
53              md: { span: 2, offset: 10 },
54              lg: { span: 6, offset: 6 }
55            })
56            .height(50).backgroundColor(0x00BFFF).textAlign(TextAlign.Center)
57        }
58      }.width('90%')
59
60      Text('Click Simulate to change the device width').fontSize(9).width('90%').fontColor(0xCCCCCC)
61      Row() {
62        Button('XS')
63          .onClick(() => {
64            this.sizeType = SizeType.XS
65          }).backgroundColor(0x317aff)
66        Button('SM')
67          .onClick(() => {
68            this.sizeType = SizeType.SM
69          }).backgroundColor(0x317aff)
70        Button('MD')
71          .onClick(() => {
72            this.sizeType = SizeType.MD
73          }).backgroundColor(0x317aff)
74        Button('LG')
75          .onClick(() => {
76            this.sizeType = SizeType.LG
77          }).backgroundColor(0x317aff)
78      }
79    }.width('100%').margin({ top: 5 })
80  }
81}
82```
83
84## ts代码段
85
86代码段-ts:
87
88**示例:**
89
90```js
91// js代码段:
92// xxx.ets
93@Entry
94@Component
95struct GridContainerExample {
96  @State sizeType: SizeType = SizeType.XS
97
98  build() {
99    Column({ space: 5 }) {
100      GridContainer({ columns: 12, sizeType: this.sizeType, gutter: 10, margin: 20 }) {
101        Row() {
102          Text('1')
103            .useSizeType({
104              xs: { span: 6, offset: 0 },
105              sm: { span: 2, offset: 0 },
106              md: { span: 2, offset: 0 },
107              lg: { span: 2, offset: 0 }
108            })
109            .height(50).backgroundColor(0x4682B4).textAlign(TextAlign.Center)
110          Text('2')
111            .useSizeType({
112              xs: { span: 2, offset: 6 },
113              sm: { span: 6, offset: 2 },
114              md: { span: 2, offset: 2 },
115              lg: { span: 2, offset: 2 }
116            })
117            .height(50).backgroundColor(0x00BFFF).textAlign(TextAlign.Center)
118          Text('3')
119            .useSizeType({
120              xs: { span: 2, offset: 8 },
121              sm: { span: 2, offset: 8 },
122              md: { span: 6, offset: 4 },
123              lg: { span: 2, offset: 4 }
124            })
125            .height(50).backgroundColor(0x4682B4).textAlign(TextAlign.Center)
126          Text('4')
127            .useSizeType({
128              xs: { span: 2, offset: 10 },
129              sm: { span: 2, offset: 10 },
130              md: { span: 2, offset: 10 },
131              lg: { span: 6, offset: 6 }
132            })
133            .height(50).backgroundColor(0x00BFFF).textAlign(TextAlign.Center)
134        }
135      }.width('90%')
136
137      Text('Click Simulate to change the device width').fontSize(9).width('90%').fontColor(0xCCCCCC)
138      Row() {
139        Button('XS')
140          .onClick(() => {
141            this.sizeType = SizeType.XS
142          }).backgroundColor(0x317aff)
143        Button('SM')
144          .onClick(() => {
145            this.sizeType = SizeType.SM
146          }).backgroundColor(0x317aff)
147        Button('MD')
148          .onClick(() => {
149            this.sizeType = SizeType.MD
150          }).backgroundColor(0x317aff)
151        Button('LG')
152          .onClick(() => {
153            this.sizeType = SizeType.LG
154          }).backgroundColor(0x317aff)
155      }
156    }.width('100%').margin({ top: 5 })
157  }
158}
159```
160
161## JavaScript代码段
162
163代码段-JavaScript:
164
165**示例:**
166
167```JavaScript
168// js代码段:
169// xxx.ets
170@Entry
171@Component
172struct GridContainerExample {
173  @State sizeType: SizeType = SizeType.XS
174
175  build() {
176    Column({ space: 5 }) {
177      GridContainer({ columns: 12, sizeType: this.sizeType, gutter: 10, margin: 20 }) {
178        Row() {
179          Text('1')
180            .useSizeType({
181              xs: { span: 6, offset: 0 },
182              sm: { span: 2, offset: 0 },
183              md: { span: 2, offset: 0 },
184              lg: { span: 2, offset: 0 }
185            })
186            .height(50).backgroundColor(0x4682B4).textAlign(TextAlign.Center)
187          Text('2')
188            .useSizeType({
189              xs: { span: 2, offset: 6 },
190              sm: { span: 6, offset: 2 },
191              md: { span: 2, offset: 2 },
192              lg: { span: 2, offset: 2 }
193            })
194            .height(50).backgroundColor(0x00BFFF).textAlign(TextAlign.Center)
195          Text('3')
196            .useSizeType({
197              xs: { span: 2, offset: 8 },
198              sm: { span: 2, offset: 8 },
199              md: { span: 6, offset: 4 },
200              lg: { span: 2, offset: 4 }
201            })
202            .height(50).backgroundColor(0x4682B4).textAlign(TextAlign.Center)
203          Text('4')
204            .useSizeType({
205              xs: { span: 2, offset: 10 },
206              sm: { span: 2, offset: 10 },
207              md: { span: 2, offset: 10 },
208              lg: { span: 6, offset: 6 }
209            })
210            .height(50).backgroundColor(0x00BFFF).textAlign(TextAlign.Center)
211        }
212      }.width('90%')
213
214      Text('Click Simulate to change the device width').fontSize(9).width('90%').fontColor(0xCCCCCC)
215      Row() {
216        Button('XS')
217          .onClick(() => {
218            this.sizeType = SizeType.XS
219          }).backgroundColor(0x317aff)
220        Button('SM')
221          .onClick(() => {
222            this.sizeType = SizeType.SM
223          }).backgroundColor(0x317aff)
224        Button('MD')
225          .onClick(() => {
226            this.sizeType = SizeType.MD
227          }).backgroundColor(0x317aff)
228        Button('LG')
229          .onClick(() => {
230            this.sizeType = SizeType.LG
231          }).backgroundColor(0x317aff)
232      }
233    }.width('100%').margin({ top: 5 })
234  }
235}
236```
237
238## javascript代码段
239
240代码段-javascript:
241
242**示例:**
243
244```javascript
245// js代码段:
246// xxx.ets
247@Entry
248@Component
249struct GridContainerExample {
250  @State sizeType: SizeType = SizeType.XS
251
252  build() {
253    Column({ space: 5 }) {
254      GridContainer({ columns: 12, sizeType: this.sizeType, gutter: 10, margin: 20 }) {
255        Row() {
256          Text('1')
257            .useSizeType({
258              xs: { span: 6, offset: 0 },
259              sm: { span: 2, offset: 0 },
260              md: { span: 2, offset: 0 },
261              lg: { span: 2, offset: 0 }
262            })
263            .height(50).backgroundColor(0x4682B4).textAlign(TextAlign.Center)
264          Text('2')
265            .useSizeType({
266              xs: { span: 2, offset: 6 },
267              sm: { span: 6, offset: 2 },
268              md: { span: 2, offset: 2 },
269              lg: { span: 2, offset: 2 }
270            })
271            .height(50).backgroundColor(0x00BFFF).textAlign(TextAlign.Center)
272          Text('3')
273            .useSizeType({
274              xs: { span: 2, offset: 8 },
275              sm: { span: 2, offset: 8 },
276              md: { span: 6, offset: 4 },
277              lg: { span: 2, offset: 4 }
278            })
279            .height(50).backgroundColor(0x4682B4).textAlign(TextAlign.Center)
280          Text('4')
281            .useSizeType({
282              xs: { span: 2, offset: 10 },
283              sm: { span: 2, offset: 10 },
284              md: { span: 2, offset: 10 },
285              lg: { span: 6, offset: 6 }
286            })
287            .height(50).backgroundColor(0x00BFFF).textAlign(TextAlign.Center)
288        }
289      }.width('90%')
290
291      Text('Click Simulate to change the device width').fontSize(9).width('90%').fontColor(0xCCCCCC)
292      Row() {
293        Button('XS')
294          .onClick(() => {
295            this.sizeType = SizeType.XS
296          }).backgroundColor(0x317aff)
297        Button('SM')
298          .onClick(() => {
299            this.sizeType = SizeType.SM
300          }).backgroundColor(0x317aff)
301        Button('MD')
302          .onClick(() => {
303            this.sizeType = SizeType.MD
304          }).backgroundColor(0x317aff)
305        Button('LG')
306          .onClick(() => {
307            this.sizeType = SizeType.LG
308          }).backgroundColor(0x317aff)
309      }
310    }.width('100%').margin({ top: 5 })
311  }
312}
313```
314
315## TypeScript代码段
316
317代码段-TypeScript:
318
319**示例:**
320
321```TypeScript
322// js代码段:
323// xxx.ets
324@Entry
325@Component
326struct GridContainerExample {
327  @State sizeType: SizeType = SizeType.XS
328
329  build() {
330    Column({ space: 5 }) {
331      GridContainer({ columns: 12, sizeType: this.sizeType, gutter: 10, margin: 20 }) {
332        Row() {
333          Text('1')
334            .useSizeType({
335              xs: { span: 6, offset: 0 },
336              sm: { span: 2, offset: 0 },
337              md: { span: 2, offset: 0 },
338              lg: { span: 2, offset: 0 }
339            })
340            .height(50).backgroundColor(0x4682B4).textAlign(TextAlign.Center)
341          Text('2')
342            .useSizeType({
343              xs: { span: 2, offset: 6 },
344              sm: { span: 6, offset: 2 },
345              md: { span: 2, offset: 2 },
346              lg: { span: 2, offset: 2 }
347            })
348            .height(50).backgroundColor(0x00BFFF).textAlign(TextAlign.Center)
349          Text('3')
350            .useSizeType({
351              xs: { span: 2, offset: 8 },
352              sm: { span: 2, offset: 8 },
353              md: { span: 6, offset: 4 },
354              lg: { span: 2, offset: 4 }
355            })
356            .height(50).backgroundColor(0x4682B4).textAlign(TextAlign.Center)
357          Text('4')
358            .useSizeType({
359              xs: { span: 2, offset: 10 },
360              sm: { span: 2, offset: 10 },
361              md: { span: 2, offset: 10 },
362              lg: { span: 6, offset: 6 }
363            })
364            .height(50).backgroundColor(0x00BFFF).textAlign(TextAlign.Center)
365        }
366      }.width('90%')
367
368      Text('Click Simulate to change the device width').fontSize(9).width('90%').fontColor(0xCCCCCC)
369      Row() {
370        Button('XS')
371          .onClick(() => {
372            this.sizeType = SizeType.XS
373          }).backgroundColor(0x317aff)
374        Button('SM')
375          .onClick(() => {
376            this.sizeType = SizeType.SM
377          }).backgroundColor(0x317aff)
378        Button('MD')
379          .onClick(() => {
380            this.sizeType = SizeType.MD
381          }).backgroundColor(0x317aff)
382        Button('LG')
383          .onClick(() => {
384            this.sizeType = SizeType.LG
385          }).backgroundColor(0x317aff)
386      }
387    }.width('100%').margin({ top: 5 })
388  }
389}
390```
391
392## typescript代码段
393
394代码段-typescript:
395
396**示例:**
397
398```typescript
399// typescript代码段:
400// xxx.ets
401@Entry
402@Component
403struct GridContainerExample {
404  @State sizeType: SizeType = SizeType.XS
405
406  build() {
407    Column({ space: 5 }) {
408      GridContainer({ columns: 12, sizeType: this.sizeType, gutter: 10, margin: 20 }) {
409        Row() {
410          Text('1')
411            .useSizeType({
412              xs: { span: 6, offset: 0 },
413              sm: { span: 2, offset: 0 },
414              md: { span: 2, offset: 0 },
415              lg: { span: 2, offset: 0 }
416            })
417            .height(50).backgroundColor(0x4682B4).textAlign(TextAlign.Center)
418          Text('2')
419            .useSizeType({
420              xs: { span: 2, offset: 6 },
421              sm: { span: 6, offset: 2 },
422              md: { span: 2, offset: 2 },
423              lg: { span: 2, offset: 2 }
424            })
425            .height(50).backgroundColor(0x00BFFF).textAlign(TextAlign.Center)
426          Text('3')
427            .useSizeType({
428              xs: { span: 2, offset: 8 },
429              sm: { span: 2, offset: 8 },
430              md: { span: 6, offset: 4 },
431              lg: { span: 2, offset: 4 }
432            })
433            .height(50).backgroundColor(0x4682B4).textAlign(TextAlign.Center)
434          Text('4')
435            .useSizeType({
436              xs: { span: 2, offset: 10 },
437              sm: { span: 2, offset: 10 },
438              md: { span: 2, offset: 10 },
439              lg: { span: 6, offset: 6 }
440            })
441            .height(50).backgroundColor(0x00BFFF).textAlign(TextAlign.Center)
442        }
443      }.width('90%')
444
445      Text('Click Simulate to change the device width').fontSize(9).width('90%').fontColor(0xCCCCCC)
446      Row() {
447        Button('XS')
448          .onClick(() => {
449            this.sizeType = SizeType.XS
450          }).backgroundColor(0x317aff)
451        Button('SM')
452          .onClick(() => {
453            this.sizeType = SizeType.SM
454          }).backgroundColor(0x317aff)
455        Button('MD')
456          .onClick(() => {
457            this.sizeType = SizeType.MD
458          }).backgroundColor(0x317aff)
459        Button('LG')
460          .onClick(() => {
461            this.sizeType = SizeType.LG
462          }).backgroundColor(0x317aff)
463      }
464    }.width('100%').margin({ top: 5 })
465  }
466}
467```
468
469
470## 无标注代码段
471无标注代码段:
472
473**示例:**
474
475```
476// 无标识代码段:
477// xxx.ets
478@Entry
479@Component
480struct GridContainerExample {
481  @State sizeType: SizeType = SizeType.XS
482
483  build() {
484    Column({ space: 5 }) {
485      GridContainer({ columns: 12, sizeType: this.sizeType, gutter: 10, margin: 20 }) {
486        Row() {
487          Text('1')
488            .useSizeType({
489              xs: { span: 6, offset: 0 },
490              sm: { span: 2, offset: 0 },
491              md: { span: 2, offset: 0 },
492              lg: { span: 2, offset: 0 }
493            })
494            .height(50).backgroundColor(0x4682B4).textAlign(TextAlign.Center)
495          Text('2')
496            .useSizeType({
497              xs: { span: 2, offset: 6 },
498              sm: { span: 6, offset: 2 },
499              md: { span: 2, offset: 2 },
500              lg: { span: 2, offset: 2 }
501            })
502            .height(50).backgroundColor(0x00BFFF).textAlign(TextAlign.Center)
503          Text('3')
504            .useSizeType({
505              xs: { span: 2, offset: 8 },
506              sm: { span: 2, offset: 8 },
507              md: { span: 6, offset: 4 },
508              lg: { span: 2, offset: 4 }
509            })
510            .height(50).backgroundColor(0x4682B4).textAlign(TextAlign.Center)
511          Text('4')
512            .useSizeType({
513              xs: { span: 2, offset: 10 },
514              sm: { span: 2, offset: 10 },
515              md: { span: 2, offset: 10 },
516              lg: { span: 6, offset: 6 }
517            })
518            .height(50).backgroundColor(0x00BFFF).textAlign(TextAlign.Center)
519        }
520      }.width('90%')
521
522      Text('Click Simulate to change the device width').fontSize(9).width('90%').fontColor(0xCCCCCC)
523      Row() {
524        Button('XS')
525          .onClick(() => {
526            this.sizeType = SizeType.XS
527          }).backgroundColor(0x317aff)
528        Button('SM')
529          .onClick(() => {
530            this.sizeType = SizeType.SM
531          }).backgroundColor(0x317aff)
532        Button('MD')
533          .onClick(() => {
534            this.sizeType = SizeType.MD
535          }).backgroundColor(0x317aff)
536        Button('LG')
537          .onClick(() => {
538            this.sizeType = SizeType.LG
539          }).backgroundColor(0x317aff)
540      }
541    }.width('100%').margin({ top: 5 })
542  }
543}
544```
545
546## 代码段标注 nocheck
547
548**示例:**
549
550<!--code_no_check-->
551```ts
552// 标注nocheck代码段:
553// xxx.ets
554@Entry
555@Component
556struct GridContainerExample {
557  @State sizeType: SizeType = SizeType.XS
558
559  build() {
560    Column({ space: 5 }) {
561      GridContainer({ columns: 12, sizeType: this.sizeType, gutter: 10, margin: 20 }) {
562        Row() {
563          Text('1')
564            .useSizeType({
565              xs: { span: 6, offset: 0 },
566              sm: { span: 2, offset: 0 },
567              md: { span: 2, offset: 0 },
568              lg: { span: 2, offset: 0 }
569            })
570            .height(50).backgroundColor(0x4682B4).textAlign(TextAlign.Center)
571          Text('2')
572            .useSizeType({
573              xs: { span: 2, offset: 6 },
574              sm: { span: 6, offset: 2 },
575              md: { span: 2, offset: 2 },
576              lg: { span: 2, offset: 2 }
577            })
578            .height(50).backgroundColor(0x00BFFF).textAlign(TextAlign.Center)
579          Text('3')
580            .useSizeType({
581              xs: { span: 2, offset: 8 },
582              sm: { span: 2, offset: 8 },
583              md: { span: 6, offset: 4 },
584              lg: { span: 2, offset: 4 }
585            })
586            .height(50).backgroundColor(0x4682B4).textAlign(TextAlign.Center)
587          Text('4')
588            .useSizeType({
589              xs: { span: 2, offset: 10 },
590              sm: { span: 2, offset: 10 },
591              md: { span: 2, offset: 10 },
592              lg: { span: 6, offset: 6 }
593            })
594            .height(50).backgroundColor(0x00BFFF).textAlign(TextAlign.Center)
595        }
596      }.width('90%')
597
598      Text('Click Simulate to change the device width').fontSize(9).width('90%').fontColor(0xCCCCCC)
599      Row() {
600        Button('XS')
601          .onClick(() => {
602            this.sizeType = SizeType.XS
603          }).backgroundColor(0x317aff)
604        Button('SM')
605          .onClick(() => {
606            this.sizeType = SizeType.SM
607          }).backgroundColor(0x317aff)
608        Button('MD')
609          .onClick(() => {
610            this.sizeType = SizeType.MD
611          }).backgroundColor(0x317aff)
612        Button('LG')
613          .onClick(() => {
614            this.sizeType = SizeType.LG
615          }).backgroundColor(0x317aff)
616      }
617    }.width('100%').margin({ top: 5 })
618  }
619}
620```
621
622## 废弃接口<sup>(deprecated)</sup>
623
624> **说明:**
625>
626> 从 API version 9开始支持,从API version 12开始废弃。
627
628**示例:**
629```js
630// 废弃接口代码段:
631// xxx.ets
632@Entry
633@Component
634struct GridContainerExample {
635  @State sizeType: SizeType = SizeType.XS
636
637  build() {
638    Column({ space: 5 }) {
639      GridContainer({ columns: 12, sizeType: this.sizeType, gutter: 10, margin: 20 }) {
640        Row() {
641          Text('1')
642            .useSizeType({
643              xs: { span: 6, offset: 0 },
644              sm: { span: 2, offset: 0 },
645              md: { span: 2, offset: 0 },
646              lg: { span: 2, offset: 0 }
647            })
648            .height(50).backgroundColor(0x4682B4).textAlign(TextAlign.Center)
649          Text('2')
650            .useSizeType({
651              xs: { span: 2, offset: 6 },
652              sm: { span: 6, offset: 2 },
653              md: { span: 2, offset: 2 },
654              lg: { span: 2, offset: 2 }
655            })
656            .height(50).backgroundColor(0x00BFFF).textAlign(TextAlign.Center)
657          Text('3')
658            .useSizeType({
659              xs: { span: 2, offset: 8 },
660              sm: { span: 2, offset: 8 },
661              md: { span: 6, offset: 4 },
662              lg: { span: 2, offset: 4 }
663            })
664            .height(50).backgroundColor(0x4682B4).textAlign(TextAlign.Center)
665          Text('4')
666            .useSizeType({
667              xs: { span: 2, offset: 10 },
668              sm: { span: 2, offset: 10 },
669              md: { span: 2, offset: 10 },
670              lg: { span: 6, offset: 6 }
671            })
672            .height(50).backgroundColor(0x00BFFF).textAlign(TextAlign.Center)
673        }
674      }.width('90%')
675
676      Text('Click Simulate to change the device width').fontSize(9).width('90%').fontColor(0xCCCCCC)
677      Row() {
678        Button('XS')
679          .onClick(() => {
680            this.sizeType = SizeType.XS
681          }).backgroundColor(0x317aff)
682        Button('SM')
683          .onClick(() => {
684            this.sizeType = SizeType.SM
685          }).backgroundColor(0x317aff)
686        Button('MD')
687          .onClick(() => {
688            this.sizeType = SizeType.MD
689          }).backgroundColor(0x317aff)
690        Button('LG')
691          .onClick(() => {
692            this.sizeType = SizeType.LG
693          }).backgroundColor(0x317aff)
694      }
695    }.width('100%').margin({ top: 5 })
696  }
697}
698```