-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
1316 lines (843 loc) · 159 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge" >
<link rel="dns-prefetch" href="https://sticky-finger.github.io">
<title>学习Blog</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="keywords" content="博客">
<meta property="og:type" content="website">
<meta property="og:title" content="学习Blog">
<meta property="og:url" content="https://sticky-finger.github.io/index.html">
<meta property="og:site_name" content="学习Blog">
<meta property="og:locale" content="zh-Hans">
<meta name="twitter:card" content="summary">
<link rel="alternative" href="/atom.xml" title="学习Blog" type="application/atom+xml">
<link rel="icon" href="/favicon.png">
<link rel="stylesheet" type="text/css" href="/./main.fc7158.css">
<style type="text/css">
#container.show {
background: linear-gradient(200deg,#a0cfe4,#e8c37e);
}
</style>
</head>
<body>
<div id="container" q-class="show:isCtnShow">
<canvas id="anm-canvas" class="anm-canvas"></canvas>
<div class="left-col" q-class="show:isShow">
<div class="overlay" style="background: #4d4d4d"></div>
<div class="intrude-less">
<header id="header" class="inner">
<a href="/" class="profilepic">
<img src="assets/sxy_avatar.jpg" class="js-avatar">
</a>
<hgroup>
<h1 class="header-author"><a href="/">Sticky-Finger</a></h1>
</hgroup>
<p class="header-subtitle">随便写写</p>
<nav class="header-menu">
<ul>
<li><a href="/">主页</a></li>
</ul>
</nav>
<nav class="header-smart-menu">
<a q-on="click: openSlider(e, 'innerArchive')" href="javascript:void(0)" target="_self">所有文章</a>
<a q-on="click: openSlider(e, 'aboutme')" href="javascript:void(0)" target="_self">关于我</a>
</nav>
<nav class="header-nav">
<div class="social">
<a class="github" target="_blank" href="https://github.com/Sticky-Finger" title="github"><i class="icon-github"></i></a>
<!-- <a class="github" href="https://github.com/Sticky-Finger" target="_blank" rel="noopener" title="github"><i class="icon-github"></i></a> -->
<a class="zhihu" target="_blank" href="https://www.zhihu.com/people/si-jia-29/activities" title="zhihu"><i class="icon-zhihu"></i></a>
<!-- <a class="zhihu" href="https://www.zhihu.com/people/si-jia-29/activities" target="_blank" rel="noopener" title="zhihu"><i class="icon-zhihu"></i></a> -->
</div>
</nav>
</header>
</div>
</div>
<div class="mid-col" q-class="show:isShow,hide:isShow|isFalse">
<nav id="mobile-nav">
<div class="overlay js-overlay" style="background: #4d4d4d"></div>
<div class="btnctn js-mobile-btnctn">
<div class="slider-trigger list" q-on="click: openSlider(e)"><i class="icon icon-sort"></i></div>
</div>
<div class="intrude-less">
<header id="header" class="inner">
<div class="profilepic">
<img src="assets/sxy_avatar.jpg" class="js-avatar">
</div>
<hgroup>
<h1 class="header-author js-header-author">Sticky-Finger</h1>
</hgroup>
<p class="header-subtitle"><i class="icon icon-quo-left"></i>随便写写<i class="icon icon-quo-right"></i></p>
<nav class="header-nav">
<div class="social">
<a class="github" target="_blank" href="https://github.com/Sticky-Finger" title="github"><i class="icon-github"></i></a>
<!-- <a class="github" href="https://github.com/Sticky-Finger" target="_blank" rel="noopener" title="github"><i class="icon-github"></i></a> -->
<a class="zhihu" target="_blank" href="https://www.zhihu.com/people/si-jia-29/activities" title="zhihu"><i class="icon-zhihu"></i></a>
<!-- <a class="zhihu" href="https://www.zhihu.com/people/si-jia-29/activities" target="_blank" rel="noopener" title="zhihu"><i class="icon-zhihu"></i></a> -->
</div>
</nav>
<nav class="header-menu js-header-menu">
<ul style="width: 50%">
<li style="width: 100%"><a href="/">主页</a></li>
</ul>
</nav>
</header>
</div>
<div class="mobile-mask" style="display:none" q-show="isShow"></div>
</nav>
<div id="wrapper" class="body-wrap">
<div class="menu-l">
<div class="canvas-wrap">
<canvas data-colors="#eaeaea" data-sectionHeight="100" data-contentId="js-content" id="myCanvas1" class="anm-canvas"></canvas>
</div>
<div id="js-content" class="content-ll">
<article id="post-46-严格策略" class="article article-type-post article-index" itemscope itemprop="blogPost">
<div class="article-inner">
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2019/12/04/46-%E4%B8%A5%E6%A0%BC%E7%AD%96%E7%95%A5/">46 严格策略</a>
</h1>
<a href="/2019/12/04/46-%E4%B8%A5%E6%A0%BC%E7%AD%96%E7%95%A5/" class="archive-article-date">
<time datetime="2019-12-04T10:54:07.000Z" itemprop="datePublished"><i class="icon-calendar icon"></i>2019-12-04</time>
</a>
</header>
<div class="article-entry" itemprop="articleBody">
<p>执行最严格的类型检查规则,并处理报错</p>
<p>// tsconfig.json</p>
<p>{<br> …<br> “compilerOptions”: {<br> …<br> “strict”: true,<br> “noImplicitAny”: true,<br> …<br> /* Additional Checks */<br> “noUnusedLocals”: true,<br> “noUnusedParameters”: true,<br> “noImplicitReturns”: true,<br> “noFallthroughCasesInSwitch”: true,<br> },<br>}<br>报错增多,处理报错</p>
</div>
<div class="article-info article-info-index">
<div class="article-tag tagcloud">
<i class="icon-price-tags icon"></i>
<ul class="article-tag-list">
<li class="article-tag-list-item">
<a href="javascript:void(0)" target="_blank" rel="noopener" class="js-tag article-tag-list-link color1">TypeScript</a>
</li>
</ul>
</div>
<p class="article-more-link">
<a class="article-more-a" href="/2019/12/04/46-%E4%B8%A5%E6%A0%BC%E7%AD%96%E7%95%A5/">展开全文 >></a>
</p>
<div class="clearfix"></div>
</div>
</div>
</article>
<aside class="wrap-side-operation">
<div class="mod-side-operation">
<div class="jump-container" id="js-jump-container" style="display:none;">
<a href="javascript:void(0)" target="_blank" rel="noopener" class="mod-side-operation__jump-to-top">
<i class="icon-font icon-back"></i>
</a>
<div id="js-jump-plan-container" class="jump-plan-container" style="top: -11px;">
<i class="icon-font icon-plane jump-plane"></i>
</div>
</div>
</div>
</aside>
<article id="post-45-宽松策略" class="article article-type-post article-index" itemscope itemprop="blogPost">
<div class="article-inner">
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2019/12/04/45-%E5%AE%BD%E6%9D%BE%E7%AD%96%E7%95%A5/">45 宽松策略</a>
</h1>
<a href="/2019/12/04/45-%E5%AE%BD%E6%9D%BE%E7%AD%96%E7%95%A5/" class="archive-article-date">
<time datetime="2019-12-04T10:53:17.000Z" itemprop="datePublished"><i class="icon-calendar icon"></i>2019-12-04</time>
</a>
</header>
<div class="article-entry" itemprop="articleBody">
<blockquote>
<p>将js、jsx文件重命名为ts、tsx文件,并且使用最宽松的类型检查规则,在不修改代码的前提下,是我们的工程能够跑起来</p>
</blockquote>
<a class="article-more-a" href="/2019/12/04/45-%E5%AE%BD%E6%9D%BE%E7%AD%96%E7%95%A5/#more">more >></a>
</div>
<div class="article-info article-info-index">
<div class="article-tag tagcloud">
<i class="icon-price-tags icon"></i>
<ul class="article-tag-list">
<li class="article-tag-list-item">
<a href="javascript:void(0)" target="_blank" rel="noopener" class="js-tag article-tag-list-link color1">TypeScript</a>
</li>
</ul>
</div>
<p class="article-more-link">
<a class="article-more-a" href="/2019/12/04/45-%E5%AE%BD%E6%9D%BE%E7%AD%96%E7%95%A5/">展开全文 >></a>
</p>
<div class="clearfix"></div>
</div>
</div>
</article>
<aside class="wrap-side-operation">
<div class="mod-side-operation">
<div class="jump-container" id="js-jump-container" style="display:none;">
<a href="javascript:void(0)" target="_blank" rel="noopener" class="mod-side-operation__jump-to-top">
<i class="icon-font icon-back"></i>
</a>
<div id="js-jump-plan-container" class="jump-plan-container" style="top: -11px;">
<i class="icon-font icon-plane jump-plane"></i>
</div>
</div>
</div>
</aside>
<article id="post-44-共存策略" class="article article-type-post article-index" itemscope itemprop="blogPost">
<div class="article-inner">
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2019/12/04/44-%E5%85%B1%E5%AD%98%E7%AD%96%E7%95%A5/">44 共存策略</a>
</h1>
<a href="/2019/12/04/44-%E5%85%B1%E5%AD%98%E7%AD%96%E7%95%A5/" class="archive-article-date">
<time datetime="2019-12-04T10:52:30.000Z" itemprop="datePublished"><i class="icon-calendar icon"></i>2019-12-04</time>
</a>
</header>
<div class="article-entry" itemprop="articleBody">
<p>将一个js项目逐步迁移到ts</p>
<p>共存策略:原来的js代码不动,新增的代码用ts编写</p>
<a class="article-more-a" href="/2019/12/04/44-%E5%85%B1%E5%AD%98%E7%AD%96%E7%95%A5/#more">more >></a>
</div>
<div class="article-info article-info-index">
<div class="article-tag tagcloud">
<i class="icon-price-tags icon"></i>
<ul class="article-tag-list">
<li class="article-tag-list-item">
<a href="javascript:void(0)" target="_blank" rel="noopener" class="js-tag article-tag-list-link color1">TypeScript</a>
</li>
</ul>
</div>
<p class="article-more-link">
<a class="article-more-a" href="/2019/12/04/44-%E5%85%B1%E5%AD%98%E7%AD%96%E7%95%A5/">展开全文 >></a>
</p>
<div class="clearfix"></div>
</div>
</div>
</article>
<aside class="wrap-side-operation">
<div class="mod-side-operation">
<div class="jump-container" id="js-jump-container" style="display:none;">
<a href="javascript:void(0)" target="_blank" rel="noopener" class="mod-side-operation__jump-to-top">
<i class="icon-font icon-back"></i>
</a>
<div id="js-jump-plan-container" class="jump-plan-container" style="top: -11px;">
<i class="icon-font icon-plane jump-plane"></i>
</div>
</div>
</div>
</aside>
<article id="post-41-搭建Vue开发环境" class="article article-type-post article-index" itemscope itemprop="blogPost">
<div class="article-inner">
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2019/12/04/41-%E6%90%AD%E5%BB%BAVue%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83/">41 搭建Vue开发环境</a>
</h1>
<a href="/2019/12/04/41-%E6%90%AD%E5%BB%BAVue%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83/" class="archive-article-date">
<time datetime="2019-12-04T10:41:10.000Z" itemprop="datePublished"><i class="icon-calendar icon"></i>2019-12-04</time>
</a>
</header>
<div class="article-entry" itemprop="articleBody">
<h1 id="一、基于hello-world工程"><a href="#一、基于hello-world工程" class="headerlink" title="一、基于hello world工程"></a>一、基于hello world工程</h1><ul>
<li><p>1)安装vue:<code>npm i vue</code></p>
<ul>
<li>vue自带了声明文件,不用额外装</li>
</ul>
</li>
<li><p>2)/src/index.ts</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">import Vue from 'vue';</span><br><span class="line"></span><br><span class="line">let app1 = new Vue({</span><br><span class="line"> el: '.app',</span><br><span class="line"> data: {</span><br><span class="line"> name: 'TypeScript',</span><br><span class="line"> },</span><br><span class="line"> template: `<h1>Hello {{ name }}</h1>`,</span><br><span class="line">});</span><br></pre></td></tr></table></figure>
</li>
<li><p>3)<code>npm start</code>运行该项目</p>
<ul>
<li>浏览器console提示:当前使用的版本是一个运行时版本,缺少编译器。需要在webpack中引入一个完全的版本</li>
</ul>
</li>
</ul>
<a class="article-more-a" href="/2019/12/04/41-%E6%90%AD%E5%BB%BAVue%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83/#more">more >></a>
</div>
<div class="article-info article-info-index">
<div class="article-tag tagcloud">
<i class="icon-price-tags icon"></i>
<ul class="article-tag-list">
<li class="article-tag-list-item">
<a href="javascript:void(0)" target="_blank" rel="noopener" class="js-tag article-tag-list-link color1">TypeScript</a>
</li>
<li class="article-tag-list-item">
<a href="javascript:void(0)" target="_blank" rel="noopener" class="js-tag article-tag-list-link color4">Vue</a>
</li>
</ul>
</div>
<p class="article-more-link">
<a class="article-more-a" href="/2019/12/04/41-%E6%90%AD%E5%BB%BAVue%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83/">展开全文 >></a>
</p>
<div class="clearfix"></div>
</div>
</div>
</article>
<aside class="wrap-side-operation">
<div class="mod-side-operation">
<div class="jump-container" id="js-jump-container" style="display:none;">
<a href="javascript:void(0)" target="_blank" rel="noopener" class="mod-side-operation__jump-to-top">
<i class="icon-font icon-back"></i>
</a>
<div id="js-jump-plan-container" class="jump-plan-container" style="top: -11px;">
<i class="icon-font icon-plane jump-plane"></i>
</div>
</div>
</div>
</aside>
<article id="post-38-搭建服务端开发环境" class="article article-type-post article-index" itemscope itemprop="blogPost">
<div class="article-inner">
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2019/12/04/38-%E6%90%AD%E5%BB%BA%E6%9C%8D%E5%8A%A1%E7%AB%AF%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83/">38 搭建服务端开发环境</a>
</h1>
<a href="/2019/12/04/38-%E6%90%AD%E5%BB%BA%E6%9C%8D%E5%8A%A1%E7%AB%AF%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83/" class="archive-article-date">
<time datetime="2019-12-04T10:39:57.000Z" itemprop="datePublished"><i class="icon-calendar icon"></i>2019-12-04</time>
</a>
</header>
<div class="article-entry" itemprop="articleBody">
<p>基于express搭建</p>
<ul>
<li><p>1)全局安装express应用生成器</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm i -g express-generator</span><br></pre></td></tr></table></figure>
</li>
<li><p>2)生成一个express应用</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">express ts-express</span><br></pre></td></tr></table></figure>
</li>
<li><p>3)进入该项目目录,安装依赖</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">cd ts-express</span><br><span class="line">npm i</span><br></pre></td></tr></table></figure>
</li>
</ul>
<blockquote>
<p>一般的项目到此就搭建好了(可以运行npm start启动),ts的还需要以下步骤</p>
</blockquote>
<ul>
<li>4)安装ts</li>
</ul>
<a class="article-more-a" href="/2019/12/04/38-%E6%90%AD%E5%BB%BA%E6%9C%8D%E5%8A%A1%E7%AB%AF%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83/#more">more >></a>
</div>
<div class="article-info article-info-index">
<div class="article-tag tagcloud">
<i class="icon-price-tags icon"></i>
<ul class="article-tag-list">
<li class="article-tag-list-item">
<a href="javascript:void(0)" target="_blank" rel="noopener" class="js-tag article-tag-list-link color1">TypeScript</a>
</li>
<li class="article-tag-list-item">
<a href="javascript:void(0)" target="_blank" rel="noopener" class="js-tag article-tag-list-link color3">node.js</a>
</li>
<li class="article-tag-list-item">
<a href="javascript:void(0)" target="_blank" rel="noopener" class="js-tag article-tag-list-link color3">express</a>
</li>
</ul>
</div>
<p class="article-more-link">
<a class="article-more-a" href="/2019/12/04/38-%E6%90%AD%E5%BB%BA%E6%9C%8D%E5%8A%A1%E7%AB%AF%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83/">展开全文 >></a>
</p>
<div class="clearfix"></div>
</div>
</div>
</article>
<aside class="wrap-side-operation">
<div class="mod-side-operation">
<div class="jump-container" id="js-jump-container" style="display:none;">
<a href="javascript:void(0)" target="_blank" rel="noopener" class="mod-side-operation__jump-to-top">
<i class="icon-font icon-back"></i>
</a>
<div id="js-jump-plan-container" class="jump-plan-container" style="top: -11px;">
<i class="icon-font icon-plane jump-plane"></i>
</div>
</div>
</div>
</aside>
<article id="post-37-Redux与类型" class="article article-type-post article-index" itemscope itemprop="blogPost">
<div class="article-inner">
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2019/12/04/37-Redux%E4%B8%8E%E7%B1%BB%E5%9E%8B/">37 Redux与类型</a>
</h1>
<a href="/2019/12/04/37-Redux%E4%B8%8E%E7%B1%BB%E5%9E%8B/" class="archive-article-date">
<time datetime="2019-12-04T10:39:00.000Z" itemprop="datePublished"><i class="icon-calendar icon"></i>2019-12-04</time>
</a>
</header>
<div class="article-entry" itemprop="articleBody">
<h2 id="安装了哪些包"><a href="#安装了哪些包" class="headerlink" title="安装了哪些包"></a>安装了哪些包</h2><ul>
<li>redux</li>
<li>react-redux</li>
<li>redux-thunk</li>
</ul>
<a class="article-more-a" href="/2019/12/04/37-Redux%E4%B8%8E%E7%B1%BB%E5%9E%8B/#more">more >></a>
</div>
<div class="article-info article-info-index">
<div class="article-tag tagcloud">
<i class="icon-price-tags icon"></i>
<ul class="article-tag-list">
<li class="article-tag-list-item">
<a href="javascript:void(0)" target="_blank" rel="noopener" class="js-tag article-tag-list-link color1">TypeScript</a>
</li>
<li class="article-tag-list-item">
<a href="javascript:void(0)" target="_blank" rel="noopener" class="js-tag article-tag-list-link color1">React</a>
</li>
<li class="article-tag-list-item">
<a href="javascript:void(0)" target="_blank" rel="noopener" class="js-tag article-tag-list-link color1">Redux</a>
</li>
</ul>
</div>
<p class="article-more-link">
<a class="article-more-a" href="/2019/12/04/37-Redux%E4%B8%8E%E7%B1%BB%E5%9E%8B/">展开全文 >></a>
</p>
<div class="clearfix"></div>
</div>
</div>
</article>
<aside class="wrap-side-operation">
<div class="mod-side-operation">
<div class="jump-container" id="js-jump-container" style="display:none;">
<a href="javascript:void(0)" target="_blank" rel="noopener" class="mod-side-operation__jump-to-top">
<i class="icon-font icon-back"></i>
</a>
<div id="js-jump-plan-container" class="jump-plan-container" style="top: -11px;">
<i class="icon-font icon-plane jump-plane"></i>
</div>
</div>
</div>
</aside>
<article id="post-36-列表渲染与路由" class="article article-type-post article-index" itemscope itemprop="blogPost">
<div class="article-inner">
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2019/12/04/36-%E5%88%97%E8%A1%A8%E6%B8%B2%E6%9F%93%E4%B8%8E%E8%B7%AF%E7%94%B1/">36 列表渲染与路由</a>
</h1>
<a href="/2019/12/04/36-%E5%88%97%E8%A1%A8%E6%B8%B2%E6%9F%93%E4%B8%8E%E8%B7%AF%E7%94%B1/" class="archive-article-date">
<time datetime="2019-12-04T10:38:00.000Z" itemprop="datePublished"><i class="icon-calendar icon"></i>2019-12-04</time>
</a>
</header>
<div class="article-entry" itemprop="articleBody">
<h2 id="列表渲染"><a href="#列表渲染" class="headerlink" title="列表渲染"></a>列表渲染</h2><p>问题:在使用antd的Form时,用Form.create()(表单组件)注意事项:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">// Props</span><br><span class="line">interface Props extends FormComponentProps {</span><br><span class="line"> onDataChange(data: EmployeeResponse): void;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line">// Component</span><br><span class="line">class QueryForm extends Component<Props, EmployeeRequest> {</span><br><span class="line">...</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line">// Form.create</span><br><span class="line">const WrappedQueryForm = Form.create<Props>({})(QueryForm);</span><br></pre></td></tr></table></figure>
<ul>
<li>不使用Form.create则没有这些:<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">// Props</span><br><span class="line">interface Props {</span><br><span class="line"> onDataChange(data: EmployeeResponse): void;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line">// Component</span><br><span class="line">class QueryForm extends Component<Props, EmployeeRequest> {</span><br><span class="line">...</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line">// export</span><br><span class="line">export default QueryForm;</span><br></pre></td></tr></table></figure>
</li>
</ul>
<h2 id="添加路由"><a href="#添加路由" class="headerlink" title="添加路由"></a>添加路由</h2>
<a class="article-more-a" href="/2019/12/04/36-%E5%88%97%E8%A1%A8%E6%B8%B2%E6%9F%93%E4%B8%8E%E8%B7%AF%E7%94%B1/#more">more >></a>
</div>
<div class="article-info article-info-index">
<div class="article-tag tagcloud">
<i class="icon-price-tags icon"></i>
<ul class="article-tag-list">
<li class="article-tag-list-item">
<a href="javascript:void(0)" target="_blank" rel="noopener" class="js-tag article-tag-list-link color1">TypeScript</a>
</li>
<li class="article-tag-list-item">
<a href="javascript:void(0)" target="_blank" rel="noopener" class="js-tag article-tag-list-link color1">React</a>
</li>
</ul>
</div>
<p class="article-more-link">
<a class="article-more-a" href="/2019/12/04/36-%E5%88%97%E8%A1%A8%E6%B8%B2%E6%9F%93%E4%B8%8E%E8%B7%AF%E7%94%B1/">展开全文 >></a>
</p>
<div class="clearfix"></div>
</div>
</div>
</article>
<aside class="wrap-side-operation">
<div class="mod-side-operation">
<div class="jump-container" id="js-jump-container" style="display:none;">
<a href="javascript:void(0)" target="_blank" rel="noopener" class="mod-side-operation__jump-to-top">
<i class="icon-font icon-back"></i>
</a>
<div id="js-jump-plan-container" class="jump-plan-container" style="top: -11px;">
<i class="icon-font icon-plane jump-plane"></i>
</div>
</div>
</div>
</aside>
<article id="post-35-事件处理与数据请求" class="article article-type-post article-index" itemscope itemprop="blogPost">
<div class="article-inner">
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2019/12/04/35-%E4%BA%8B%E4%BB%B6%E5%A4%84%E7%90%86%E4%B8%8E%E6%95%B0%E6%8D%AE%E8%AF%B7%E6%B1%82/">35 事件处理与数据请求</a>
</h1>
<a href="/2019/12/04/35-%E4%BA%8B%E4%BB%B6%E5%A4%84%E7%90%86%E4%B8%8E%E6%95%B0%E6%8D%AE%E8%AF%B7%E6%B1%82/" class="archive-article-date">
<time datetime="2019-12-04T10:37:12.000Z" itemprop="datePublished"><i class="icon-calendar icon"></i>2019-12-04</time>
</a>
</header>
<div class="article-entry" itemprop="articleBody">
<h2 id="搭建界面"><a href="#搭建界面" class="headerlink" title="搭建界面"></a>搭建界面</h2><p>目录结构:</p>
<ul>
<li>src/<ul>
<li>components/ <ul>
<li>employee/ #员工界面 </li>
<li>App.tsx</li>
</ul>
</li>
</ul>
</li>
</ul>
<h2 id="代码"><a href="#代码" class="headerlink" title="代码"></a>代码</h2><ul>
<li>/src/components/employee/QueryForm.</li>
</ul>
<h2 id="过程"><a href="#过程" class="headerlink" title="过程"></a>过程</h2><ul>
<li>UI组件添加事件和状态(react的state),状态的类型(就是接口请求和响应数据的格式的一部分),将其抽离出来抽象成interface</li>
</ul>
<a class="article-more-a" href="/2019/12/04/35-%E4%BA%8B%E4%BB%B6%E5%A4%84%E7%90%86%E4%B8%8E%E6%95%B0%E6%8D%AE%E8%AF%B7%E6%B1%82/#more">more >></a>
</div>
<div class="article-info article-info-index">
<p class="article-more-link">
<a class="article-more-a" href="/2019/12/04/35-%E4%BA%8B%E4%BB%B6%E5%A4%84%E7%90%86%E4%B8%8E%E6%95%B0%E6%8D%AE%E8%AF%B7%E6%B1%82/">展开全文 >></a>
</p>
<div class="clearfix"></div>
</div>
</div>
</article>
<aside class="wrap-side-operation">
<div class="mod-side-operation">
<div class="jump-container" id="js-jump-container" style="display:none;">
<a href="javascript:void(0)" target="_blank" rel="noopener" class="mod-side-operation__jump-to-top">
<i class="icon-font icon-back"></i>
</a>
<div id="js-jump-plan-container" class="jump-plan-container" style="top: -11px;">
<i class="icon-font icon-plane jump-plane"></i>
</div>
</div>
</div>
</aside>
<article id="post-34-组件与类型(2):高阶组件与Hooks" class="article article-type-post article-index" itemscope itemprop="blogPost">
<div class="article-inner">
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2019/12/04/34-%E7%BB%84%E4%BB%B6%E4%B8%8E%E7%B1%BB%E5%9E%8B%EF%BC%882%EF%BC%89%EF%BC%9A%E9%AB%98%E9%98%B6%E7%BB%84%E4%BB%B6%E4%B8%8EHooks/">34 组件与类型(2):高阶组件与Hooks</a>
</h1>
<a href="/2019/12/04/34-%E7%BB%84%E4%BB%B6%E4%B8%8E%E7%B1%BB%E5%9E%8B%EF%BC%882%EF%BC%89%EF%BC%9A%E9%AB%98%E9%98%B6%E7%BB%84%E4%BB%B6%E4%B8%8EHooks/" class="archive-article-date">
<time datetime="2019-12-04T10:36:16.000Z" itemprop="datePublished"><i class="icon-calendar icon"></i>2019-12-04</time>
</a>
</header>
<div class="article-entry" itemprop="articleBody">
<table>
<thead>
<tr>
<th>组件复用方式</th>
<th>优势</th>
<th>劣势</th>
<th>状态</th>
</tr>
</thead>
<tbody><tr>
<td>类组件(class)</td>
<td>发展时间长,接受度广泛</td>
<td>只能继承父类</td>
<td>传统模式,长期存在</td>
</tr>
<tr>
<td>Mixin</td>
<td>可以复制任意对象的任意多个方法</td>
<td>组件相互依赖、耦合,可能产生冲突,不利于维护</td>
<td>被抛弃</td>
</tr>
<tr>
<td>高阶组件(HOC)</td>
<td>利用装饰器模式,在不改变组件的基础上,动态地为其添加新的能力</td>
<td>嵌套过多调试困难,需要遵守某些约定(不改变原始组件,透传props等)</td>
<td>能力强大,应用广泛</td>
</tr>
<tr>
<td>Hooks</td>
<td>代替class,多个Hooks互不影响,避免嵌套地狱,开发效率高</td>
<td>切换到新思维需要成本</td>
<td>React未来</td>
</tr>
</tbody></table>
<a class="article-more-a" href="/2019/12/04/34-%E7%BB%84%E4%BB%B6%E4%B8%8E%E7%B1%BB%E5%9E%8B%EF%BC%882%EF%BC%89%EF%BC%9A%E9%AB%98%E9%98%B6%E7%BB%84%E4%BB%B6%E4%B8%8EHooks/#more">more >></a>
</div>
<div class="article-info article-info-index">
<div class="article-tag tagcloud">
<i class="icon-price-tags icon"></i>
<ul class="article-tag-list">
<li class="article-tag-list-item">
<a href="javascript:void(0)" target="_blank" rel="noopener" class="js-tag article-tag-list-link color1">TypeScript</a>
</li>
<li class="article-tag-list-item">
<a href="javascript:void(0)" target="_blank" rel="noopener" class="js-tag article-tag-list-link color1">React</a>
</li>
<li class="article-tag-list-item">
<a href="javascript:void(0)" target="_blank" rel="noopener" class="js-tag article-tag-list-link color1">Hooks</a>
</li>
</ul>
</div>
<p class="article-more-link">
<a class="article-more-a" href="/2019/12/04/34-%E7%BB%84%E4%BB%B6%E4%B8%8E%E7%B1%BB%E5%9E%8B%EF%BC%882%EF%BC%89%EF%BC%9A%E9%AB%98%E9%98%B6%E7%BB%84%E4%BB%B6%E4%B8%8EHooks/">展开全文 >></a>
</p>
<div class="clearfix"></div>
</div>
</div>
</article>
<aside class="wrap-side-operation">
<div class="mod-side-operation">
<div class="jump-container" id="js-jump-container" style="display:none;">
<a href="javascript:void(0)" target="_blank" rel="noopener" class="mod-side-operation__jump-to-top">
<i class="icon-font icon-back"></i>
</a>
<div id="js-jump-plan-container" class="jump-plan-container" style="top: -11px;">
<i class="icon-font icon-plane jump-plane"></i>
</div>
</div>
</div>
</aside>
<article id="post-33-组件与类型(1):函数组件与类组件" class="article article-type-post article-index" itemscope itemprop="blogPost">
<div class="article-inner">
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2019/12/04/33-%E7%BB%84%E4%BB%B6%E4%B8%8E%E7%B1%BB%E5%9E%8B%EF%BC%881%EF%BC%89%EF%BC%9A%E5%87%BD%E6%95%B0%E7%BB%84%E4%BB%B6%E4%B8%8E%E7%B1%BB%E7%BB%84%E4%BB%B6/">33 组件与类型(1):函数组件与类组件</a>
</h1>
<a href="/2019/12/04/33-%E7%BB%84%E4%BB%B6%E4%B8%8E%E7%B1%BB%E5%9E%8B%EF%BC%881%EF%BC%89%EF%BC%9A%E5%87%BD%E6%95%B0%E7%BB%84%E4%BB%B6%E4%B8%8E%E7%B1%BB%E7%BB%84%E4%BB%B6/" class="archive-article-date">
<time datetime="2019-12-04T10:35:19.000Z" itemprop="datePublished"><i class="icon-calendar icon"></i>2019-12-04</time>
</a>
</header>
<div class="article-entry" itemprop="articleBody">
<h2 id="函数组件"><a href="#函数组件" class="headerlink" title="函数组件"></a>函数组件</h2><ul>
<li><p>React.FC</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">import React from 'react';</span><br><span class="line">import Button from 'antd';</span><br><span class="line"></span><br><span class="line">interface Greeting {</span><br><span class="line"> name: string;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line">const Hello: React.FC<Greeting> = (props) => <Button>Hello {props.name}</Button></span><br></pre></td></tr></table></figure></li>
<li><p>使用React.FC和不使用的区别:</p>
<ul>
<li>React.FC优点:<ul>
<li>1)隐含声明了children属性 <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">const Hello: React.FC<Greeting> = ({</span><br><span class="line"> ...,</span><br><span class="line"> children,</span><br><span class="line">}) => <Button>Hello {props.name}</Button></span><br></pre></td></tr></table></figure></li>
<li>2)函数组件定义静态属性时,会给一些自动提示<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">interface Greeting {</span><br><span class="line"> name: string;</span><br><span class="line"> // !使用React.FC定义的函数组件,在使用默认属性时,props的属性类型声明,要加上`可选符号--?`</span><br><span class="line"> // 不使用React.FC定义的,没有这种问题</span><br><span class="line"> firstName?: string;</span><br><span class="line"> lastName?: string;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line">const Hello: React.FC<Greeting> = ...</span><br><span class="line"></span><br><span class="line">Hello.defaultProps = {</span><br><span class="line"> firstName: '',</span><br><span class="line"> lastName: '',</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
</li>
</ul>
</li>
</ul>
</li>
<li><p>总结:使用React.FC并没有给我们带来明显的好处,而且这个类型可能会被官方弃用。所以我们还是建议使用常规的定义方式</p>
</li>
</ul>
<a class="article-more-a" href="/2019/12/04/33-%E7%BB%84%E4%BB%B6%E4%B8%8E%E7%B1%BB%E5%9E%8B%EF%BC%881%EF%BC%89%EF%BC%9A%E5%87%BD%E6%95%B0%E7%BB%84%E4%BB%B6%E4%B8%8E%E7%B1%BB%E7%BB%84%E4%BB%B6/#more">more >></a>
</div>
<div class="article-info article-info-index">
<div class="article-tag tagcloud">
<i class="icon-price-tags icon"></i>
<ul class="article-tag-list">
<li class="article-tag-list-item">
<a href="javascript:void(0)" target="_blank" rel="noopener" class="js-tag article-tag-list-link color1">TypeScript</a>
</li>