Repository navigation
Expand file tree
/
Copy pathsearch.xml
More file actions
2891 lines (2645 loc) · 396 KB
/
Copy pathsearch.xml
File metadata and controls
2891 lines (2645 loc) · 396 KB
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
<?xml version="1.0" encoding="utf-8"?>
<search>
<entry>
<title>IIS部署cesium文档</title>
<url>/2022/12/07/cesium/da39cf3f3db8/</url>
<content><![CDATA[<h1 id="部署效果"><a href="#部署效果" class="headerlink" title="部署效果"></a>部署效果</h1><p><a id="DeploymentEffect">部署效果</a></p>
<p><img src="https://files.catbox.moe/7iosdt.png" alt="IIS部署cesium文档"></p>
<h1 id="IIS"><a href="#IIS" class="headerlink" title="IIS"></a>IIS</h1><p> <img src="https://files.catbox.moe/kng7w5.png" alt="iis界面截图"></p>
<p> IIS,全称Internet infomation services、是微软官方的一款网站管理工具。</p>
<h1 id="cesium文件"><a href="#cesium文件" class="headerlink" title="cesium文件"></a>cesium文件</h1><p>前端开发需要用到cesium.js库文件的话、可以通过<a href="https://github.com/CesiumGS/cesium/releases/download/1.100/Cesium-1.100.zip">官方链接:https://github.com/CesiumGS/cesium/releases/download/1.100/Cesium-1.100.zip</a>进行下载。</p>
<p>当然会存在网速较慢的情况导致下载失败、你也可以通过百度网盘链接进行下载:</p>
<div class="note danger modern"><p> <a href="https://pan.baidu.com/s/1TckAoWkY1s7-58QbPIQKRQ?pwd=yozo">链接:https://pan.baidu.com/s/1TckAoWkY1s7-58QbPIQKRQ?pwd=yozo</a><br>提取码:yozo </p>
</div>
<p>下载文件解压缩之后、主要文件内容如下:<br><img src="https://files.catbox.moe/uiw3dt.png" alt="下载解压缩文件目录截图"></p>
<p>我们需要部署的文件夹路径为:<strong>Cesium-1.100/Build/Documentation</strong></p>
<p>其中包含的即为cesium官方文档的全部文件。我们可以将它放置到一个自定义文件夹中,方便后续引入。<br><img src="https://files.catbox.moe/mbok9m.png" alt="cesium官方文档documention文件夹"></p>
<h1 id="win11系统基本配置"><a href="#win11系统基本配置" class="headerlink" title="win11系统基本配置"></a>win11系统基本配置</h1><p>所有文件、准备就绪以后,我们首先需要打开IIS服务。</p>
<ol>
<li>在win11电脑上找到:<strong>Windows功能</strong></li>
<li>按图勾选对应功能:<br><img src="https://files.catbox.moe/sdeogh.png" alt="IIS所需Windows系统功能配置"></li>
<li>安装完毕后、就可以通过IIS新建网站了。</li>
</ol>
<h1 id="新建网站"><a href="#新建网站" class="headerlink" title="新建网站"></a>新建网站</h1><ul>
<li><p>通过Windows搜索框,搜索IIS即可出现IIS应用、管理员模式打开后,于左侧“网站”字样上点击鼠标右键<br><img src="https://files.catbox.moe/8yza23.png" alt="IIS、新建网站、鼠标右键截图"></p>
</li>
<li><p><img src="https://files.catbox.moe/g2bely.png" alt="IIS添加网站配置"></p>
</li>
</ul>
<p>之后启动、会出现503的情况:<br><img src="https://files.catbox.moe/f6ionn.png" alt="503的情况"></p>
<p>解决方案:<br><img src="https://files.catbox.moe/cui8fq.png" alt="503解决方案"></p>
<h1 id="访问"><a href="#访问" class="headerlink" title="访问"></a>访问</h1><p><a href="http://localhost:8088/">http://localhost:8088</a></p>
<p><a href="#DeploymentEffect">部署效果</a></p>
]]></content>
<categories>
<category>cesium</category>
</categories>
<tags>
<tag>cesium</tag>
</tags>
</entry>
<entry>
<title>TypeScript入门教程(一)</title>
<url>/2021/09/24/TypeScript/854698b90236/</url>
<content><![CDATA[<h1 id="TypeScript学习"><a href="#TypeScript学习" class="headerlink" title="TypeScript学习"></a>TypeScript学习</h1><p> TypeScript 的发展已经深入到前端社区的方方面面了,任何规模的项目都或多或少得到了 TypeScript 的支持。同时vue3在经过vue2之后的发展过程中采用了TypeScript进行了重构,也让使用vue作为主力开发框架的开发者们,需要学习TypeScript来适应日常的开发过程。</p>
<p> 同时也有赖于TypeScript这门语言的优点:</p>
<ol>
<li>完全兼容于JavaScript</li>
<li>适用于任何规模</li>
</ol>
<p> 使得我们的开发的代码能够更加严谨和健壮!</p>
<span id="more"></span>
<h2 id="学习内容及教程推荐"><a href="#学习内容及教程推荐" class="headerlink" title="学习内容及教程推荐"></a>学习内容及教程推荐</h2><ol>
<li><a href="https://ts.xcatliu.com/introduction/what-is-typescript.html">TypeScript入门教程</a> 中文文档,很容易阅读和理解,对于新手十分友好</li>
<li><a href="https://www.typescriptlang.org/docs/handbook/intro.html">typescript中文官网–手书</a> 英文文档,阅读体验对国人不是很友好</li>
<li><a href="https://www.tslang.cn/docs/home.html">typescript中文文档教程</a> 当前最新typescript版本为 “typescript”: “^4.3.2”,文档最新版本只更新到v3.1版本,是有滞后的。</li>
</ol>
<h2 id="除了实现-ECMAScript-标准之外,TypeScript-团队也推进了诸多语法提案"><a href="#除了实现-ECMAScript-标准之外,TypeScript-团队也推进了诸多语法提案" class="headerlink" title="除了实现 ECMAScript 标准之外,TypeScript 团队也推进了诸多语法提案"></a>除了实现 ECMAScript 标准之外,TypeScript 团队也推进了诸多语法提案</h2><h3 id="可选链操作符(-)"><a href="#可选链操作符(-)" class="headerlink" title="可选链操作符(?.)"></a>可选链操作符(?.)</h3><pre><code> 参考链接: https://zh.javascript.info/optional-chaining
</code></pre>
<h3 id="空值合并操作符"><a href="#空值合并操作符" class="headerlink" title="空值合并操作符"></a>空值合并操作符</h3><pre><code> 参考链接: https://zh.javascript.info/nullish-coalescing-operator
</code></pre>
<h3 id="throw表达式"><a href="#throw表达式" class="headerlink" title="throw表达式"></a>throw表达式</h3><pre><code> throw 语句抛出一个错误。
</code></pre>
<p>当错误发生时, JavaScript 会停止执行并抛出错误信息。</p>
<p>描述这种情况的技术术语是:JavaScript 将抛出一个错误。</p>
<p>throw 语句创建自定义错误。</p>
<p>技术术语是: 抛出异常。</p>
<p>异常可以是 JavaScript 字符串、数字、逻辑值或对象:</p>
<h3 id="正则匹配索引"><a href="#正则匹配索引" class="headerlink" title="正则匹配索引"></a>正则匹配索引</h3><h2 id="typescript的安装"><a href="#typescript的安装" class="headerlink" title="typescript的安装"></a>typescript的安装</h2><h3 id="使用命令行工具"><a href="#使用命令行工具" class="headerlink" title="使用命令行工具"></a>使用命令行工具</h3><figure class="highlight cmake"><table><tr><td class="code"><pre><code class="hljs cmake">npm <span class="hljs-keyword">install</span> -g typescript<br></code></pre></td></tr></table></figure>
<h3 id="hello-ts"><a href="#hello-ts" class="headerlink" title="hello.ts"></a>hello.ts</h3><p> 1.新建一个简单函数:hello.ts</p>
<figure class="highlight typescript"><table><tr><td class="code"><pre><code class="hljs typescript"> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">sayHello</span>(<span class="hljs-params">person: <span class="hljs-built_in">string</span></span>) </span>{<br> <span class="hljs-keyword">return</span> <span class="hljs-string">'hello,'</span>+ person;<br><br>}<br><span class="hljs-keyword">let</span> user = <span class="hljs-string">'tom'</span>;<br><span class="hljs-built_in">console</span>.log(sayHello(user));<br></code></pre></td></tr></table></figure>
<p> 2.安装好typescript后,在命令行终端键入以下命令: <strong>tsc hello.ts</strong></p>
<p> 即可看到显示的hello.js文件</p>
<p> <img src="https://cdn.jsdelivr.net/gh/mhist/hexoImage@main/img/20210924160047d.png" alt="hello.ts"><br> <img src="https://cdn.jsdelivr.net/gh/mhist/hexoImage@main/img/20210924160612hellojs.png" alt="hello.js"></p>
<blockquote>
<p>TypeScript 只会在编译时对类型进行静态检查,如果发现有错误,编译的时候就会报错。而在运行时,与普通的 JavaScript 文件一样,不会对类型进行检查。</p>
</blockquote>
<p> 简单来说,typescript主要是在编译过程中检查错误的存在,在没有进行其他设置的情况下,即使错误,也会继续生成相应的js文件,当然这对于使用typescript的用户来说是需要避免的,开发着需要在ts编译阶段报错时终止(ts文件→js文件)这一过程,需要进行以下<strong><strong>配置</strong></strong></p>
<p> 可以在 tsconfig.json 中配置 noEmitOnError 即可。关于 tsconfig.json,<a href="https://segmentfault.com/a/1190000021421461?utm_source=tag-newest">参考思否教程</a>。</p>
<h1 id="typescript基础"><a href="#typescript基础" class="headerlink" title="typescript基础"></a>typescript基础</h1><h2 id="原始数据类型"><a href="#原始数据类型" class="headerlink" title="原始数据类型"></a>原始数据类型</h2><p> 原始数据类型现今总共有: 7种 = 5种 + 2种<br> 5种: 布尔值,数值,字符串,null, undefined<br> 2种: Symbol (ES6新类型); BigInt(ES10新类型) </p>
<h3 id="布尔值"><a href="#布尔值" class="headerlink" title="布尔值"></a>布尔值</h3><figure class="highlight lasso"><table><tr><td class="code"><pre><code class="hljs lasso"><span class="hljs-keyword">let</span> isDone: <span class="hljs-built_in">boolean</span> = <span class="hljs-literal">false</span>;<br></code></pre></td></tr></table></figure>
<p> 很明显可以正常编译,那么采用构造函数的形式呢?</p>
<figure class="highlight lasso"><table><tr><td class="code"><pre><code class="hljs lasso"><span class="hljs-keyword">let</span> createdByNewBoolean: <span class="hljs-built_in">boolean</span> = <span class="hljs-literal">new</span> <span class="hljs-built_in">Boolean</span>(<span class="hljs-number">1</span>);<br></code></pre></td></tr></table></figure>
<p><a href="https://www.typescriptlang.org/zh/play#code/DYUwLgBAxgTiCGYQBMBCBPAciA7qg9vqPAHYBcEARocSRALwQm4QFEIkAUAjAJQDcQA">代码预览—布尔值</a></p>
<blockquote>
<p> error TS2322: Type ‘Boolean’ is not assignable to type ‘boolean’.<br> ‘boolean’ is a primitive, but ‘Boolean’ is a wrapper object. Prefer using ‘boolean’ when possible.</p>
</blockquote>
<blockquote>
<p>Boolean 是对应布尔值的引用类型。要创建一个 Boolean 对象,就使用 Boolean 构造函数并传入<br>true 或 false</p>
</blockquote>
<p>即通过构造函数new Boolean(1)的结果实际是布尔值对象,而不是布尔值,所以会出现类型错误,理解原始布尔值和 Boolean 对象之间的区别非常重要,强烈建议永远不要使用后者.</p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><code class="hljs javascript"><span class="hljs-keyword">let</span> createdByNewBoolean: <span class="hljs-built_in">Boolean</span> = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Boolean</span>(<span class="hljs-number">1</span>);<br></code></pre></td></tr></table></figure>
<p><a href="https://www.typescriptlang.org/zh/play#code/DYUwLgBAxgTiCGYQBMBCBPAciA7qg9vqPAHYBcEBRCJEAvBCbpYcSQBQCMAlANxA">代码预览—布尔对象</a></p>
<h3 id="数字"><a href="#数字" class="headerlink" title="数字"></a>数字</h3><figure class="highlight maxima"><table><tr><td class="code"><pre><code class="hljs maxima"><span class="hljs-built_in">let</span> decLiteral: number = <span class="hljs-number">6</span>;<br><span class="hljs-built_in">let</span> hexLiteral: number = <span class="hljs-number">0xf00d</span>;<br>// ES6 中的二进制表示法<br><span class="hljs-built_in">let</span> binaryLiteral: number = <span class="hljs-number">0b1010</span>;<br>// ES6 中的八进制表示法<br><span class="hljs-built_in">let</span> octalLiteral: number = <span class="hljs-number">0o744</span>;<br><span class="hljs-built_in">let</span> notANumber: number = NaN;<br>...<br></code></pre></td></tr></table></figure>
<p><a href="https://www.typescriptlang.org/zh/play#code/DYUwLgBAJiDGAyBLMIBOBDYAuCA7ArgLYBGaEAvBAGwDcAsAFCiQAWIAHkihtnkaagoQADOwBmw4VHoMA9LIgBRAMpUIgWjlAIW6AYuUDb8YDYlQBYRgLk9AqzaNmEYolzpUATy5pMOAiTKVhxAIzDfM+SVVDU1Aa0UDE3MmcAgAe1gwTCceV34PEViAdgAWbJlLXFiwAEEAOTTUVPdBSlL0UvyYmzEbZHty6qqBIQBJXBbcNpogA">代码预览—数字</a></p>
<h3 id="void-null-undfined"><a href="#void-null-undfined" class="headerlink" title="void \ null \ undfined"></a>void \ null \ undfined</h3><pre><code>在typescript中没有空值的概念,遇到这种情况可以采用void来标识没有返回值的函数 (划重点:没有返回值的函数)
</code></pre>
<figure class="highlight actionscript"><table><tr><td class="code"><pre><code class="hljs actionscript"> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">alertName</span><span class="hljs-params">()</span>: void </span>{<br> alert(<span class="hljs-string">'My name is Tom'</span>);<br>}<br></code></pre></td></tr></table></figure>
<pre><code>声明一个void类型的变量是没有什么用处的,因为之后你只能将它赋值为null或者undfined(只在 --strictNullChecks 未指定时):
注意是变量,对于没有返回值的函数还是有必要的
</code></pre>
<blockquote>
<p>undefined 和 null 两个空类型的设计,使用上不方便,所以 通过strictNullChecks严格校验类型,让代码更安全</p>
</blockquote>
<figure class="highlight typescript"><table><tr><td class="code"><pre><code class="hljs typescript"> <span class="hljs-comment">// 两个空类型</span><br> <span class="hljs-keyword">let</span> u: <span class="hljs-literal">undefined</span> = <span class="hljs-literal">undefined</span><br> <span class="hljs-keyword">let</span> n: <span class="hljs-literal">null</span> = <span class="hljs-literal">null</span><br><br> <span class="hljs-comment">// 常见区别</span><br><span class="hljs-built_in">Number</span>(<span class="hljs-literal">null</span>) <span class="hljs-comment">// 0</span><br><span class="hljs-built_in">Number</span>(<span class="hljs-literal">undefined</span>) <span class="hljs-comment">// NaN</span><br><br><span class="hljs-keyword">let</span> age: <span class="hljs-built_in">number</span> = <span class="hljs-literal">null</span><br><span class="hljs-built_in">console</span>.log(<span class="hljs-number">5</span> + age) <span class="hljs-comment">//5</span><br><br>age = und...<br></code></pre></td></tr></table></figure>
<p><a href="https://www.typescriptlang.org/zh/play#code/PTAEhI5QqOULy9G8fRo9QLACgA2BTALqArgLlwDsATdAMwEtD1jQBeI0y64lDbQgwnVVe0brxQoQoQBx6gQcjAXMqBqJRQA5HAFsARugBOACkGoAlKAOGjB0QAYFytVpwlyVGvuOj5AQ3nC0WUC4Dm6LpYa-DooAMYA9oQAzuEYAHSo4T6aAKygANTefo5GICkevuj8Nkz2rMgR0bHoCUmpGVnoOYYgru7IYZEx8YnJJXYs9Aw6+qKY6jjoQA">空值校验预览</a></p>
<p>注意:<br>1.与 void 的区别是,undefined 和 null 是所有类型的子类型。也就是说 undefined 类型的变量,可以赋值给 number 类型的变量:<br>2.而 void 类型的变量不能赋值给 number 类型的变量:</p>
<h3 id="any"><a href="#any" class="headerlink" title="any"></a>any</h3><p> 如果是一个普通类型,在赋值过程中改变类型是不被允许的:但如果是 any 类型,则允许被赋值为任意类型。在任意值上访问任何属性都是允许的:也允许调用任何方法:变量如果在声明的时候,未指定其类型,那么它会被识别为任意值类型</p>
<h2 id="类型推论"><a href="#类型推论" class="headerlink" title="类型推论"></a>类型推论</h2><ul>
<li>类型推论: 字面意思即使,当类型没有被明确指定的时候,那么 TypeScript 会依照类* 型推论(Type Inference)的规则推断出一个类型。</li>
<li>如果定义的时候没有赋值,不管之后有没有赋值,都会被推断成 any 类型而完全不被类型检查。</li>
</ul>
<h2 id="联合类型"><a href="#联合类型" class="headerlink" title="联合类型"></a>联合类型</h2><ul>
<li>即在定义类型时可以拥有多种类型,联合类型使用 | 分隔每个类型。</li>
<li>当 TypeScript 不确定一个联合类型的变量到底是哪个类型的时候,我们只能访问此联合类型的所有类型里共有的属性或方法:</li>
</ul>
<figure class="highlight crmsh"><table><tr><td class="code"><pre><code class="hljs crmsh">function getLength(something: <span class="hljs-keyword">string</span> | <span class="hljs-keyword">number</span>): <span class="hljs-keyword">number</span> {<br> return something.length;<br>}<br><br>// index.ts(<span class="hljs-number">2</span>,<span class="hljs-number">22</span>): error TS2339: <span class="hljs-keyword">Property</span><span class="hljs-title"> </span>'length' does not exist on <span class="hljs-keyword">type</span> '<span class="hljs-keyword">string</span> | <span class="hljs-keyword">number</span>'.<br>// <span class="hljs-keyword">Property</span><span class="hljs-title"> </span>'length' does not exist on <span class="hljs-keyword">type</span> '<span class="hljs-keyword">number</span>'.<br><br></code></pre></td></tr></table></figure>
<p>当访问的不是共有属性或者方法的时候,就会报错。联合类型的变量在被赋值的时候,会根据类型推论的规则推断出一个类型:</p>
<figure class="highlight sas"><table><tr><td class="code"><pre><code class="hljs sas">let myFavoriteNumber: string | number;<br>myFavoriteNumber = <span class="hljs-string">'seven'</span>;<br>console<span class="hljs-meta">.log(</span>myFavoriteNumber.<span class="hljs-meta">length</span>); // 5<br>myFavoriteNumber = 7;<br>console<span class="hljs-meta">.log(</span>myFavoriteNumber.<span class="hljs-meta">length</span>); // 编译时报错<br><br>// <span class="hljs-meta">index</span>.ts(5,30): <span class="hljs-meta">error</span> TS2339: Property <span class="hljs-string">'length'</span> does <span class="hljs-meta">not</span> exist <span class="hljs-meta">on</span> type <span class="hljs-string">'number'</span>.<br></code></pre></td></tr></table></figure>
<blockquote>
<p>上例中,第二行的 myFavoriteNumber 被推断成了 string,访问它的 length 属性不会报错。而第四行的 myFavoriteNumber 被推断成了 number,访问它的 length 属性时就报错了。</p>
</blockquote>
<h2 id="接口-(给对象准备的自定义类型)"><a href="#接口-(给对象准备的自定义类型)" class="headerlink" title="接口 (给对象准备的自定义类型)"></a>接口 (给对象准备的自定义类型)</h2><p>实例代码:</p>
<figure class="highlight xquery"><table><tr><td class="code"><pre><code class="hljs xquery">interface Person {<br> <span class="hljs-built_in"> name</span>:<span class="hljs-built_in"> string</span>;<br> age:<span class="hljs-built_in"> number</span>;<br>}<br><br><span class="hljs-keyword">let</span> tom: Person = {<br> <span class="hljs-built_in"> name</span>: <span class="hljs-string">'Tom'</span>,<br> age: <span class="hljs-number">25</span><br>};<br></code></pre></td></tr></table></figure>
<h3 id="形状得一样"><a href="#形状得一样" class="headerlink" title="形状得一样"></a>形状得一样</h3><p>赋值的时候需要保证接口的形状必须和其指定的类型一样。</p>
<h3 id="可选属性(形状可以不一样,得加条件)"><a href="#可选属性(形状可以不一样,得加条件)" class="headerlink" title="可选属性(形状可以不一样,得加条件)"></a>可选属性(形状可以不一样,得加条件)</h3><p>当然在开发需求中也会有需要其中某一个或者某几个,不要限制的那么死板,于是就有了 <strong>可选属性</strong>,通过在“:”前添加一个“?”来表示属性的可选性,这样也可以使得限制变得宽松,形状也可以有不一致。</p>
<p>可选属性可以实现已定义属性的有或无,但是对于未定义的属性,则产生了限制,因为它有严格的形状限制,而有时候我们希望一个接口允许有任意的属性,可以使用如下方式:</p>
<figure class="highlight typescript"><table><tr><td class="code"><pre><code class="hljs typescript"><span class="hljs-keyword">interface</span> Person {<br> <span class="hljs-attr">name</span>: <span class="hljs-built_in">string</span>;<br> age?: <span class="hljs-built_in">number</span>;<br> [propName: <span class="hljs-built_in">string</span>]: <span class="hljs-built_in">any</span>;<br>}<br><br><span class="hljs-keyword">let</span> tom: Person = {<br> <span class="hljs-attr">name</span>: <span class="hljs-string">'Tom'</span>,<br> <span class="hljs-attr">gender</span>: <span class="hljs-string">'male'</span><br>};<br></code></pre></td></tr></table></figure>
<h3 id="一旦定义了任意属性,那么确定属性和可选属性的类型都必须是它的类型的子集:"><a href="#一旦定义了任意属性,那么确定属性和可选属性的类型都必须是它的类型的子集:" class="headerlink" title="一旦定义了任意属性,那么确定属性和可选属性的类型都必须是它的类型的子集:"></a>一旦定义了任意属性,那么确定属性和可选属性的类型都必须是它的类型的子集:</h3><p>在上面的例子中,我们将任意属性的类型指定为any,则name指定的字符串类型和age指定的数字类型都是any类型的子集,所以是符合要求的。</p>
<p>下面来测试一个不属于其子集的例子:</p>
<figure class="highlight xquery"><table><tr><td class="code"><pre><code class="hljs xquery">interface Person {<br> <span class="hljs-built_in"> name</span>:<span class="hljs-built_in"> string</span>;<br> age?:<span class="hljs-built_in"> number</span>;<br> [propName:<span class="hljs-built_in"> string</span>]:<span class="hljs-built_in"> string</span>;<br>}<br><br><span class="hljs-keyword">let</span> tom: Person = {<br> <span class="hljs-built_in"> name</span>: <span class="hljs-string">'Tom'</span>,<br> age: <span class="hljs-number">25</span>,<br> gender: <span class="hljs-string">'male'</span><br>};<br></code></pre></td></tr></table></figure>
<p><a href="https://www.typescriptlang.org/zh/play#code/JYOwLgpgTgZghgYwgAgArQM4HsTIN4CwAUMqciHALYQBcyGYUoA5gNzFnJzMQD8dIAK6UARtHYkyAbQAOULDIByVWvUYsAunQZMQbYgF9ixADYQwyMFkp10UbLgC8+DmQrU6AcgAq1zwBpXUm5VACYAVkDJUh4QABNoL0o4M09DViA">非其子集*–预览</a></p>
<h3 id="只读属性(readonly)"><a href="#只读属性(readonly)" class="headerlink" title="只读属性(readonly)"></a>只读属性(readonly)</h3><p> 在一些情况下,我们需要值是只读属性,当它被赋值一次以后,不能再对其进行赋值,此时可以采用readonly属性来指定。</p>
<figure class="highlight plaintext"><table><tr><td class="code"><pre><code class="hljs tsx">interface Person {<br> readonly id: number;<br> name: string;<br> age?: number;<br> [propName: string]: any;<br>}<br><br>let tom: Person = {<br> id: 89757,<br> name: 'Tom',<br> gender: 'male'<br>};<br><br>tom.id = 9527;<br><br>// index.ts(14,5): error TS2540: Cannot assign to 'id' because it is a constant or a read-only property.<br></code></pre></td></tr></table></figure>
<p> 使用readonly属性的时候,需要在定义的时候即赋值,在其拥有readonly属性之后再通过对象操作的方式进行赋值也会报错。</p>
<figure class="highlight xquery"><table><tr><td class="code"><pre><code class="hljs xquery">interface Person {<br> readonly<span class="hljs-built_in"> id</span>:<span class="hljs-built_in"> number</span>;<br> <span class="hljs-built_in"> name</span>:<span class="hljs-built_in"> string</span>;<br> age?:<span class="hljs-built_in"> number</span>;<br> [propName:<span class="hljs-built_in"> string</span>]: any;<br>}<br><br><span class="hljs-keyword">let</span> tom: Person = {<br> <span class="hljs-built_in"> name</span>: <span class="hljs-string">'Tom'</span>,<br> gender: <span class="hljs-string">'male'</span><br>};<br><br>tom<span class="hljs-built_in">.id</span> = <span class="hljs-number">89757</span>;<br><br>// index.ts(<span class="hljs-number">8</span>,<span class="hljs-number">5</span>):<span class="hljs-built_in"> error</span> TS2322: Type <span class="hljs-string">'{ name: string; gender: string; }'</span> <span class="hljs-literal">is</span><span class="hljs-built_in"> not</span> assignable <span class="hljs-keyword">to</span> type <span class="hljs-string">'Person'</span>.<br>// Property <span class="hljs-string">'id'</span> <span class="hljs-literal">is</span> missing <span class="hljs-keyword">in</span> type <span class="hljs-string">'{ name: string; gender: string; }'</span>.<br>// index.ts(<span class="hljs-number">13</span>,<span class="hljs-number">5</span>):<span class="hljs-built_in"> error</span> TS254<span class="hljs-number">0</span>: Cannot assign <span class="hljs-keyword">to</span> <span class="hljs-string">'id'</span> because it <span class="hljs-literal">is</span> a constant <span class="hljs-keyword">or</span> a read-only property.<br></code></pre></td></tr></table></figure>
<h2 id="数组类型"><a href="#数组类型" class="headerlink" title="数组类型"></a>数组类型</h2><p> 数组是日常开发中遇到的最多的数据结构之一,从它的基本方法的多样性也可以看出它的使用度是极高的。那么在typescript世界中对于数组类型的定义又会有哪些实用方式呢?</p>
<h3 id="类型-方括号-表示法"><a href="#类型-方括号-表示法" class="headerlink" title="类型+方括号 表示法"></a>类型+方括号 表示法</h3><p> 数组字面量是非常普遍的数组定义方法,在typescript中则采用了 类型+方括号的组成,一方面能够非常方便得表示数组,另一方面可以限制数组内元素得类型。</p>
<figure class="highlight inform7"><table><tr><td class="code"><pre><code class="hljs inform7">let fibonacci: number<span class="hljs-comment">[]</span> = <span class="hljs-comment">[1, 1, 2, 3, 5]</span>;<br></code></pre></td></tr></table></figure>
<blockquote>
<p>1.数组的项中不允许出现其他的类型,且数组的一些方法也会根据数组在定义时候的类型加以限制。</p>
</blockquote>
<figure class="highlight xquery"><table><tr><td class="code"><pre><code class="hljs xquery"><span class="hljs-keyword">let</span> fibonacci:<span class="hljs-built_in"> number</span>[] = [<span class="hljs-number">1</span>, <span class="hljs-string">'1'</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">5</span>];<br><br>// Type <span class="hljs-string">'string'</span> <span class="hljs-literal">is</span><span class="hljs-built_in"> not</span> assignable <span class="hljs-keyword">to</span> type <span class="hljs-string">'number'</span>.<br><br></code></pre></td></tr></table></figure>
<figure class="highlight xquery"><table><tr><td class="code"><pre><code class="hljs xquery"><span class="hljs-keyword">let</span> fibonacci:<span class="hljs-built_in"> number</span>[] = [<span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">5</span>];<br>fibonacci.push(<span class="hljs-string">'8'</span>);<br><br>// Argument <span class="hljs-keyword">of</span> type <span class="hljs-string">'"8"'</span> <span class="hljs-literal">is</span><span class="hljs-built_in"> not</span> assignable <span class="hljs-keyword">to</span> parameter <span class="hljs-keyword">of</span> type <span class="hljs-string">'number'</span>.<br><br></code></pre></td></tr></table></figure>
<p>定义一个任意类型的数组:</p>
<figure class="highlight prolog"><table><tr><td class="code"><pre><code class="hljs prolog">let list: any[] = [<span class="hljs-string">'xcatliu'</span>, <span class="hljs-number">25</span>, { website: <span class="hljs-string">'http://xcatliu.com'</span> }];<br></code></pre></td></tr></table></figure>
<h3 id="泛型"><a href="#泛型" class="headerlink" title="泛型"></a>泛型</h3><p>我们也可以使用数组泛型(Array Generic) Array<类型> 来表示数组:</p>
<figure class="highlight typescript"><table><tr><td class="code"><pre><code class="hljs typescript"><span class="hljs-keyword">let</span> fibonacci: <span class="hljs-built_in">Array</span><<span class="hljs-built_in">number</span>> = [<span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">5</span>];<br></code></pre></td></tr></table></figure>
<p><a href="http://ts.xcatliu.com/basics/type-of-array.html#%E6%95%B0%E7%BB%84%E6%B3%9B%E5%9E%8B">更加复杂的数组类型表示方式</a></p>
<h3 id="用接口表示数组"><a href="#用接口表示数组" class="headerlink" title="用接口表示数组"></a>用接口表示数组</h3> <figure class="highlight fortran"><table><tr><td class="code"><pre><code class="hljs fortran"> <span class="hljs-keyword">interface</span> NumberArray {<br> [<span class="hljs-built_in">index</span>: <span class="hljs-keyword">number</span>]: <span class="hljs-keyword">number</span>;<br>}<br>let fibonacci: NumberArray = [<span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">5</span>];<br></code></pre></td></tr></table></figure>
<p> 结合数组的特点,首先索引值必须是数字,在上述的例子中规定了属性值也为数字,所以可以将[1,1,2,3,5]赋值给fibonacci.</p>
<p> 与前两种比较而言,此种方法是比较复杂的,当然它的主要用处是用来表示<font color="red">类数组</font>。</p>
<h3 id="类数组"><a href="#类数组" class="headerlink" title="类数组"></a>类数组</h3><h4 id="类数组的概念"><a href="#类数组的概念" class="headerlink" title="类数组的概念"></a>类数组的概念</h4><p> 想要理解为什么多用比较复杂的接口来定义类数组? 首先需要了解类数组的基本概念。</p>
<blockquote>
<p><font color=plum>类数组不是数组,它的原型是对象</font></p>
</blockquote>
<figure class="highlight typescript"><table><tr><td class="code"><pre><code class="hljs typescript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">sum</span>(<span class="hljs-params"></span>) </span>{<br> <span class="hljs-keyword">let</span> args: {<br> [index: <span class="hljs-built_in">number</span>]: <span class="hljs-built_in">number</span>;<br> length: <span class="hljs-built_in">number</span>;<br> callee: <span class="hljs-built_in">Function</span>;<br> } = <span class="hljs-built_in">arguments</span>;<br>}<br><br></code></pre></td></tr></table></figure>
<p>事实上常用的类数组都有自己的接口定义,如 IArguments, NodeList, HTMLCollection 等:</p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><code class="hljs javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">sum</span>(<span class="hljs-params"></span>) </span>{<br> <span class="hljs-keyword">let</span> args: IArguments = <span class="hljs-built_in">arguments</span>;<br>}<br><br></code></pre></td></tr></table></figure>
<p>其中 IArguments 是 TypeScript 中定义好了的类型,它实际上就是:<font color=seagreen><a href="http://ts.xcatliu.com/basics/built-in-objects.html">内置对象</a></font></p>
<figure class="highlight fortran"><table><tr><td class="code"><pre><code class="hljs fortran"><span class="hljs-keyword">interface</span> IArguments {<br> [<span class="hljs-built_in">index</span>: <span class="hljs-keyword">number</span>]: <span class="hljs-built_in">any</span>;<br> length: <span class="hljs-keyword">number</span>;<br> callee: <span class="hljs-function"><span class="hljs-keyword">Function</span></span>;<br>}<br></code></pre></td></tr></table></figure>
<h2 id="函数的类型"><a href="#函数的类型" class="headerlink" title="函数的类型"></a>函数的类型</h2><p>前面提到过可以用void来表示没有返回值的函数类型,这一节,我们将学习到对于有返回值的函数应该怎么表示,函数作为编程语言里不可缺少的部分,能够利用其灵活性,给我们的代码开发过程中带来效率的提升。首先,需要重温一下原生JavaScript中对于<font color=seagreen>函数的声明方式</font>:函数声明(Function Declaration)和函数表达式(Function Expression):</p>
<figure class="highlight ada"><table><tr><td class="code"><pre><code class="hljs ada">// 函数声明(<span class="hljs-keyword">Function</span> <span class="hljs-title">Declaration)</span><br><span class="hljs-keyword">function</span> <span class="hljs-title">sum</span>(x, y) {<br> <span class="hljs-keyword">return</span> <span class="hljs-type">x</span> + y;<br>}<br><br>// 函数表达式(<span class="hljs-keyword">Function</span> <span class="hljs-title">Expression)</span><br>let mySum = <span class="hljs-keyword">function</span> <span class="hljs-title"></span>(x, y) {<br> <span class="hljs-keyword">return</span> <span class="hljs-type">x</span> + y;<br>};<br></code></pre></td></tr></table></figure>
<blockquote>
<p><font color=seagreen>一个函数有输入和输出,要在typescript中对其进行约束,需要把输入和输出都考虑到</font></p>
</blockquote>
<figure class="highlight fortran"><table><tr><td class="code"><pre><code class="hljs fortran"><span class="hljs-function"><span class="hljs-keyword">function</span></span> <span class="hljs-built_in">sum</span>(x:<span class="hljs-keyword">number</span>,y:<span class="hljs-keyword">number</span>): <span class="hljs-keyword">number</span> {<br> <span class="hljs-keyword">return</span> x+y;<br>}<br></code></pre></td></tr></table></figure>
<blockquote>
<p>注意:<font color=chocolate>输入多余的(或者少于要求的)参数,是不被允许的:</font></p>
</blockquote>
<ul>
<li><font color=seagreen>多输入参数:</font><figure class="highlight fortran"><table><tr><td class="code"><pre><code class="hljs fortran"><span class="hljs-function"><span class="hljs-keyword">function</span></span> <span class="hljs-built_in">sum</span>(x: <span class="hljs-keyword">number</span>, y: <span class="hljs-keyword">number</span>): <span class="hljs-keyword">number</span> {<br> <span class="hljs-keyword">return</span> x + y;<br>}<br><span class="hljs-built_in">sum</span>(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>);<br><br>// <span class="hljs-built_in">index</span>.ts(<span class="hljs-number">4</span>,<span class="hljs-number">1</span>): error TS2346: Supplied parameters <span class="hljs-keyword">do</span> not match <span class="hljs-built_in">any</span> signature of <span class="hljs-keyword">call</span> <span class="hljs-keyword">target</span>.<br></code></pre></td></tr></table></figure></li>
<li><font color=purple>少输入参数:</font><figure class="highlight fortran"><table><tr><td class="code"><pre><code class="hljs fortran"><span class="hljs-function"><span class="hljs-keyword">function</span></span> <span class="hljs-built_in">sum</span>(x: <span class="hljs-keyword">number</span>, y: <span class="hljs-keyword">number</span>): <span class="hljs-keyword">number</span> {<br> <span class="hljs-keyword">return</span> x + y;<br>}<br><span class="hljs-built_in">sum</span>(<span class="hljs-number">1</span>);<br><br>// <span class="hljs-built_in">index</span>.ts(<span class="hljs-number">4</span>,<span class="hljs-number">1</span>): error TS2346: Supplied parameters <span class="hljs-keyword">do</span> not match <span class="hljs-built_in">any</span> signature of <span class="hljs-keyword">call</span> <span class="hljs-keyword">target</span>.<br></code></pre></td></tr></table></figure></li>
</ul>
<h3 id="函数表达式的类型加注"><a href="#函数表达式的类型加注" class="headerlink" title="函数表达式的类型加注"></a>函数表达式的类型加注</h3><p> 函数表达式相较于函数声明式是比较复杂的,首先是因为在赋值表达式两边都有字符,实际上如果在函数表达式左侧不对类型加以约束,在编译过程是可以通过的。 为了严谨,需要在函数左侧也加以类型约束。 通过类似于ES6中的箭头函数的样式,来表示函数左侧的样式,当然其本质还是不同的,在 TypeScript 的类型定义中,=> 用来表示函数的定义,左边是输入类型,需要用括号括起来,右边是输出类型。</p>
<figure class="highlight typescript"><table><tr><td class="code"><pre><code class="hljs typescript"><span class="hljs-keyword">let</span> mySum: <span class="hljs-function">(<span class="hljs-params">x: <span class="hljs-built_in">number</span>, y: <span class="hljs-built_in">number</span></span>) =></span> <span class="hljs-built_in">number</span> = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">x: <span class="hljs-built_in">number</span>, y: <span class="hljs-built_in">number</span></span>): <span class="hljs-title">number</span> </span>{<br> <span class="hljs-keyword">return</span> x + y;<br>};<br></code></pre></td></tr></table></figure>
<p> 当然为了代码的可读性,也可以采用接口的方式定义函数</p>
<figure class="highlight typescript"><table><tr><td class="code"><pre><code class="hljs typescript"><span class="hljs-keyword">interface</span> SearchFunc {<br> (source: <span class="hljs-built_in">string</span>,<span class="hljs-attr">subString</span>: <span class="hljs-built_in">string</span>): <span class="hljs-built_in">boolean</span>;<br>}<br><br><span class="hljs-keyword">let</span> mySrarch: SearchFunc;<br><br>mySearch = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">source: <span class="hljs-built_in">string</span>, subString: <span class="hljs-built_in">string</span></span>) </span>{<br> <span class="hljs-keyword">return</span> source.search(subString) !== -<span class="hljs-number">1</span>;<br>}<br></code></pre></td></tr></table></figure>
<blockquote>
<p><font color=tomato>难点:用接口定义函数的理解</font><br> <strong><font color=orange>怎么理解用typescript接口定义函数</font></strong><br> <a href="https://www.cnblogs.com/wjaaron/p/12851994.html">typescript定义函数类型</a></p>
</blockquote>
<blockquote>
<p>个人理解:在定义接口的时候,因为是应用于函数的接口定义,所以左侧是函数的参数类型,通过冒号连接右侧的,实际是表示函数的类型的值,相当于用 “=>” 在函数表达式中的实现方式,应该是一种约定的方式。</p>
</blockquote>
<p>前文提到:在没有使用可选参数的情况下,对于函数而言,在输入端多输入参数或者是少输入参数都会产生错误,在使用<strong>可选参数</strong>时,可以放松一些对于函数输入的要求,但是也有限制。</p>
<figure class="highlight nginx"><table><tr><td class="code"><pre><code class="hljs nginx"><span class="hljs-attribute">function</span> buildName(firstName: string, <span class="hljs-literal">last</span>Name?: string) {<br> <span class="hljs-attribute">if</span> (<span class="hljs-literal">last</span>Name) {<br> <span class="hljs-attribute">return</span> firstName + <span class="hljs-string">' '</span> + <span class="hljs-literal">last</span>Name;<br> } <span class="hljs-section">else</span> {<br> <span class="hljs-attribute">return</span> firstName;<br> }<br>}<br><span class="hljs-attribute">let</span> tomcat = buildName(<span class="hljs-string">'Tom'</span>, <span class="hljs-string">'Cat'</span>);<br><span class="hljs-attribute">let</span> tom = buildName(<span class="hljs-string">'Tom'</span>);<br></code></pre></td></tr></table></figure>
<p><font color=#d76b26 >可选参数后面不允许再出现必需参数了:</font></p>
<figure class="highlight typescript"><table><tr><td class="code"><pre><code class="hljs typescript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">buildName</span>(<span class="hljs-params">firstName?: <span class="hljs-built_in">string</span>, lastName: <span class="hljs-built_in">string</span></span>) </span>{<br> <span class="hljs-keyword">if</span> (firstName) {<br> <span class="hljs-keyword">return</span> firstName + <span class="hljs-string">' '</span> + lastName;<br> } <span class="hljs-keyword">else</span> {<br> <span class="hljs-keyword">return</span> lastName;<br> }<br>}<br><span class="hljs-keyword">let</span> tomcat = buildName(<span class="hljs-string">'Tom'</span>, <span class="hljs-string">'Cat'</span>);<br><span class="hljs-keyword">let</span> tom = buildName(<span class="hljs-literal">undefined</span>, <span class="hljs-string">'Tom'</span>);<br><br><span class="hljs-comment">// index.ts(1,40): error TS1016: A required parameter cannot follow an optional parameter.</span><br></code></pre></td></tr></table></figure>
<h3 id="参数默认值"><a href="#参数默认值" class="headerlink" title="参数默认值"></a>参数默认值</h3><p>在ES6中允许给函数的参数设置默认值,在typescript会将具有默认值的参数识别为可选参数,</p>
<figure class="highlight plaintext"><table><tr><td class="code"><pre><code class="hljs tsx">function buildName(firstName: string, lastName: string = 'Cat') {<br> return firstName + ' ' + lastName;<br>}<br>let tomcat = buildName('Tom', 'Cat');<br>console.log(tomcat);<br>let tom = buildName('Tom');<br>...<br></code></pre></td></tr></table></figure>
<p><a href="https://www.typescriptlang.org/zh/play?ssl=7&ssc=17&pln=1&pc=1#code/GYVwdgxgLglg9mABAIxDANgEwHIEMC2ApgBTAwBOAzlHkQFyLXkxgDmANIurtbYQ0xatEAXkQByAMK4o4gJSIA3gFgAUIg2JyhKCHJIyVGgUKIA1BMsXuvEwG41AXzXodiKHHwQZolGix8xOIAKp7inFIy8g6qEAiUcK4AdOhwrMQeXjJyMa5Q7p6+qBg4JkGh+NFqcWAJyanpmXJAA">可选参数在后</a></p>
<p>此时就不受「<font color=purple>可选参数必须接在必需参数后面</font>」的限制了:</p>
<figure class="highlight plaintext"><table><tr><td class="code"><pre><code class="hljs tsx">function buildName(firstName: string = 'Tom', lastName: string) {<br> return firstName + ' ' + lastName;<br>}<br>let tomcat = buildName('Tom', 'Cat');<br>console.log(tomcat);<br>let cat = buildName(undefined, 'Cat');<br>console.log(cat);<br></code></pre></td></tr></table></figure>
<p><a href="https://www.typescriptlang.org/zh/play?ssl=7&ssc=18&pln=1&pc=1#code/GYVwdgxgLglg9mABAIxDANgEwHIEMC2ApgBTAwBOAzlHkQFyLXkxgDmiAvIgOQAqc+bgBpE6XNVqEGTFqwCUiAN4BYAFCINicoSghySMlRoFCiANQ9LFsRJMBuNQF816HYigCIuKJxRosksR8AsI8AMLe3HIOqhAIlHCuAHTocKzEHvheUNEubtm+qBg4JsTgmIRkYISYItwRUFExcWAJyanp2dFAA">可选参数在前</a></p>
<h3 id="剩余参数"><a href="#剩余参数" class="headerlink" title="剩余参数"></a><font color=tomato>剩余参数</font></h3><p>剩余参数,rest后面不能再有其他参数了,表示除了之前的参数外的其余的所有参数。<a href="https://es6.ruanyifeng.com/#docs/function#rest-%E5%8F%82%E6%95%B0">ES6-剩余参数</a></p>
<figure class="highlight actionscript"><table><tr><td class="code"><pre><code class="hljs actionscript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">push</span><span class="hljs-params">(array: any[], <span class="hljs-rest_arg">...items</span>: any[])</span> </span>{<br> items.forEach(<span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(item)</span> </span>{<br> array.push(item);<br> });<br>}<br><br>let a:any[]= []; <span class="hljs-comment">// 在这里,a元素在被赋值为[]时,隐式的具有any[]类型.</span><br>push(a, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>);<br>console.log(a)<br></code></pre></td></tr></table></figure>
<p>它定义了一个push函数,能将其参数加入到一个数组中。</p>
<h3 id="重载"><a href="#重载" class="headerlink" title="重载"></a><a href="http://ts.xcatliu.com/basics/type-of-function.html"><font color=chocolate>重载</font></a></h3><pre><code> 对于文章中的重载不是很理解,因为JavaScript是没有重载这一概念的,
</code></pre>
<figure class="highlight plaintext"><table><tr><td class="code"><pre><code class="hljs tsx">function reverse(x: number): number;<br>function reverse(x: string): string;<br>function reverse(x: number | string): number | string | void {<br> if (typeof x === 'number') {<br> return Number(x.to...<br></code></pre></td></tr></table></figure>
<p><a href="https://www.typescriptlang.org/zh/play#code/GYVwdgxgLglg9mABAJwKYDdXIM6oBQAeAXImCALYBGWAlCWVVgNwCwAUKJLAihlroRLYoyGGADmdRMNETWHcNHhI0mHPmKkK1ZIgA+0kWMn1tWfYdniL6ODAAmiAN7tEbxDGCI8UAJ4AHVDgvAkQAXgjEAHIGHSiaZ1d3ZLQoEGQkADkzZEIAOig4AGUjCTwaPOx-ABsYKDwo+LzVfnwKgCs7MAb4mnlkgF9EVGrcDy8fAKCQ8MiomWN4xLZklNQ0jMQCSpq6noqW9XK8zrF9-vcB9gGgA">Playground Link</a></p>
]]></content>
<categories>
<category>TypeScript</category>
</categories>
<tags>
<tag>TypeScript</tag>
</tags>
</entry>
<entry>
<title>TypeScript入门教程二</title>
<url>/2021/09/26/TypeScript/4d8aa16bcb6b/</url>
<content><![CDATA[<h1 id="typescript学习:第二部分"><a href="#typescript学习:第二部分" class="headerlink" title="typescript学习:第二部分"></a>typescript学习:第二部分</h1><p> → <a href="http://wakeweb.cloud/2021/09/24/TypeScript/854698b90236/">第一部分跳转链接</a></p>
<p>经过第一部分的学习,我们已经了解到了typescript的基本用法,同时对于其在代码健壮性,以及编译过程中即出现错误提示的有点有了更一步的了解,接下来,我们将进一步学习新的知识,体会typescript更加高级的用法。</p>
<h2 id="类型断言"><a href="#类型断言" class="headerlink" title="类型断言"></a>类型断言</h2><p> 在学习类型断言之前,需要先了解断言的具体概念,针对node语言里面也有相关断言的概念,有以下的问题:<br> <font color=orange>1.断言是一个广泛的概念吗?</font><br> <font color=seagreen>2.node断言与typescript类型断言分别都是什么?</font><br> <span id="more"></span></p>
<p> 首先可以回答第一个问题: 是,那么第二个问题就没有必要再纠结了。</p>
<p> <a href="https://www.runoob.com/w3cnote/c-assert.html">菜鸟教程–asserts断言的用法</a>.</p>
<p><font color=amber> 可以这么说:断言assert 是仅在Debug 版本起作用的宏,它用于检查”不应该”发生的情况。</font></p>
<p><font color=yellowgreen>需要注意的是,类型断言只能够「欺骗」TypeScript 编译器,无法避免运行时的错误,反而滥用类型断言可能会导致运行时错误:</font></p>
<blockquote>
<p>以下是使用断言的几个原则:<br>(1)使用断言捕捉不应该发生的非法情况。不要混淆非法情况与错误情况之间的区别,后者是必然存在的并且是一定要作出处理的。<br>(2)使用断言对函数的参数进行确认。<br>(3)在编写函数时,要进行反复的考查,并且自问:”我打算做哪些假定?”一旦确定了的假定,就要使用断言对假定进行检查。<br>(4)一般教科书都鼓励程序员们进行防错性的程序设计,但要记住这种编程风格会隐瞒错误。当进行防错性编程时,如果”不可能发生”的事情的确发生了,则要使用断言进行报警。</p>
</blockquote>
<h3 id="类型断言的用法"><a href="#类型断言的用法" class="headerlink" title="类型断言的用法"></a>类型断言的用法</h3><p>前文提到,对于断言的使用是需要慎重的。这节我们将学习断言(assert)的具体用法:<br>方法1: <font color=purple>值 as 类型</font><br>方法2: <font color=seagreen><类型>值</font></p>
<p>由于第二种方法在使用过程中可能会产生<font color=purple>歧义</font>,因为</p>
<blockquote>
<p>在 tsx 语法(React 的 jsx 语法的 ts 版)中必须使用前者,即 值 as 类型。形如 <Foo> 的语法在 tsx 中表示的是一个 ReactNode,在 ts 中除了表示类型断言之外,也可能是表示一个泛型。故建议大家在使用类型断言时,统一使用 值 as 类型 这样的语法,本书中也会贯彻这一思想。</p>
</blockquote>
<h3 id="类型断言的用途"><a href="#类型断言的用途" class="headerlink" title="类型断言的用途"></a>类型断言的用途</h3><h4 id="将一个联合类型推断为其中一个类型"><a href="#将一个联合类型推断为其中一个类型" class="headerlink" title="将一个联合类型推断为其中一个类型"></a>将一个联合类型推断为其中一个类型</h4><p>在<a href="http://wakeweb.cloud/2021/09/24/TypeScript/854698b90236/">第一部分</a>提到过,在不确定一个具有联合类型的变量具体是哪一种类型时,只能访问此联合类型的所有类型中共有的属性和方法:</p>
<figure class="highlight php"><table><tr><td class="code"><pre><code class="hljs php"><span class="hljs-class"><span class="hljs-keyword">interface</span> <span class="hljs-title">Cat</span> </span>{<br> name: <span class="hljs-keyword">string</span>;<br> run(): <span class="hljs-keyword">void</span>;<br>}<br><span class="hljs-class"><span class="hljs-keyword">interface</span> <span class="hljs-title">Fish</span> </span>{<br> name: <span class="hljs-keyword">string</span>;<br> swim(): <span class="hljs-keyword">void</span>;<br>}<br><br><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getName</span>(<span class="hljs-params">animal: Cat | Fish</span>) </span>{<br> <span class="hljs-keyword">return</span> animal.name;<br>}<br></code></pre></td></tr></table></figure>
<p>而当我们确实需要在不确定类型的时候就访问其中一个类型所特有的属性或方法,比如:</p>
<figure class="highlight pgsql"><table><tr><td class="code"><pre><code class="hljs pgsql">interface Cat {<br> <span class="hljs-type">name</span>: string;<br> run(): <span class="hljs-type">void</span>;<br>}<br>interface Fish {<br> <span class="hljs-type">name</span>: string;<br> swim(): <span class="hljs-type">void</span>;<br>}<br><br><span class="hljs-keyword">function</span> isFish(animal: Cat | Fish) {<br> <span class="hljs-keyword">if</span> (typeof animal.swim === <span class="hljs-string">'function'</span>) {<br> <span class="hljs-keyword">return</span> <span class="hljs-keyword">true</span>;<br> }<br> <span class="hljs-keyword">return</span> <span class="hljs-keyword">false</span>;<br>}<br><br>// <span class="hljs-keyword">index</span>.ts:<span class="hljs-number">11</span>:<span class="hljs-number">23</span> - error TS2339: Property <span class="hljs-string">'swim'</span> does <span class="hljs-keyword">not</span> exist <span class="hljs-keyword">on</span> <span class="hljs-keyword">type</span> <span class="hljs-string">'Cat | Fish'</span>.<br>// Property <span class="hljs-string">'swim'</span> does <span class="hljs-keyword">not</span> exist <span class="hljs-keyword">on</span> <span class="hljs-keyword">type</span> <span class="hljs-string">'Cat'</span>.<br></code></pre></td></tr></table></figure>
<p>上面的例子中,获取 animal.swim 的时候会报错。</p>
<p>此时可以使用类型断言,将 animal 断言成 Fish:</p>
<figure class="highlight typescript"><table><tr><td class="code"><pre><code class="hljs typescript"><span class="hljs-keyword">interface</span> Cat {<br> <span class="hljs-attr">name</span>: <span class="hljs-built_in">string</span>;<br> run(): <span class="hljs-built_in">void</span>;<br>}<br><span class="hljs-keyword">interface</span> Fish {<br> <span class="hljs-attr">name</span>: <span class="hljs-built_in">string</span>;<br> swim(): <span class="hljs-built_in">void</span>;<br>}<br><br><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">isFish</span>(<span class="hljs-params">animal: Cat | Fish</span>) </span>{<br> <span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> (animal <span class="hljs-keyword">as</span> Fish).swim === <span class="hljs-string">'function'</span>) {<br> <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;<br> }<br> <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;<br>}<br></code></pre></td></tr></table></figure>
<p>需要注意的是,类型断言只能够「欺骗」TypeScript 编译器,无法避免运行时的错误,反而滥用类型断言可能会导致运行时错误:</p>
<figure class="highlight pgsql"><table><tr><td class="code"><pre><code class="hljs pgsql">interface Cat {<br> <span class="hljs-type">name</span>: string;<br> run(): <span class="hljs-type">void</span>;<br>}<br>interface Fish {<br> <span class="hljs-type">name</span>: string;<br> swim(): <span class="hljs-type">void</span>;<br>}<br><span class="hljs-keyword">function</span> swim(animal: Cat | Fish) {<br> (animal <span class="hljs-keyword">as</span> Fish).swim();<br>}<br><br>const tom: Cat = {<br> <span class="hljs-type">name</span>: <span class="hljs-string">'Tom'</span>,<br> run() { console.log(<span class="hljs-string">'run'</span>)}<br>};<br>swim(tom);<br>// <span class="hljs-keyword">index</span>.ts:<span class="hljs-number">11</span>:<span class="hljs-number">23</span> - error TS2339: Property <span class="hljs-string">'swim'</span> does <span class="hljs-keyword">not</span> exist <span class="hljs-keyword">on</span> <span class="hljs-keyword">type</span> <span class="hljs-string">'Cat | Fish'</span>.<br>// Property <span class="hljs-string">'swim'</span> does <span class="hljs-keyword">not</span> exist <span class="hljs-keyword">on</span> <span class="hljs-keyword">type</span> <span class="hljs-string">'Cat'</span>.<br></code></pre></td></tr></table></figure>
<p><a href="https://www.typescriptlang.org/zh/play#code/JYOwLgpgTgZghgYwgAgMJzMg3gWAFDLIhwC2EAXMgM5hSgDmA3PoVAK4gAUAlJQG4B7YABNmeAL75QkWIhQAxYFQAW2FkVIVqtBmMJUA7sBI9+Q0fkl4YHBGGACQ1IybghjcADaV0mAD7IiircagTInG4enshwVIFKytwAdIbGPGJW+AiONMhgAiQ+GMgAvKGExGSUAOQAKgXVADTq7FzcWMjZIFQCnhBJngL0nNWt1dxW4mKpJvkk3IxAA">错误预览</a></p>
<p>首先理解一下函数 siwm函数传递参数animal,然后参数调用该类型的属性和方法。不太理解的地方可以查看上方的错误预览。</p>
<p>原因是 (animal as Fish).swim() 这段代码隐藏了 animal 可能为 Cat 的情况,将 animal 直接断言为 Fish 了,而 TypeScript 编译器信任了我们的断言,故在调用 swim() 时没有编译错误。</p>
<p>可是 swim 函数接受的参数是 Cat | Fish,一旦传入的参数是 Cat 类型的变量,由于 Cat 上没有 swim 方法,就会导致运行时错误了。</p>
<p>总之,使用类型断言时一定要格外小心,尽量避免断言后调用方法或引用深层属性,以减少不必要的运行时错误。</p>
<h4 id="将一个父类断言为更加具体的子类"><a href="#将一个父类断言为更加具体的子类" class="headerlink" title="将一个父类断言为更加具体的子类"></a>将一个父类断言为更加具体的子类</h4><p> 当类之间有继承关系时,类型断言也是常见的。</p>
<figure class="highlight scala"><table><tr><td class="code"><pre><code class="hljs scala"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ApiError</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Error</span> </span>{<br> code: number = <span class="hljs-number">0</span>;<br>}<br><br><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">HttpError</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Error</span> </span>{<br> statusCode: number = <span class="hljs-number">200</span>;<br>}<br><br>function isApiError(error: <span class="hljs-type">Error</span>) {<br> <span class="hljs-keyword">if</span>(typeof (error as <span class="hljs-type">ApiError</span>).code === <span class="hljs-symbol">'numbe</span>r') {<br> <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;<br> }<br><br><span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;<br>}<br></code></pre></td></tr></table></figure>
<p>在<font color=red>isApiError函数</font>中,它用于实现传入的错误是不是ApiError类型。</p>
<p>有的情况下 ApiError 和 HttpError 不是一个真正的类,而只是一个 TypeScript 的接口(interface),接口是一个类型,不是一个真正的值,它在编译结果中会被删除,当然就无法使用 instanceof 来做运行时判断了:</p>
<figure class="highlight typescript"><table><tr><td class="code"><pre><code class="hljs typescript"><span class="hljs-keyword">interface</span> ApiError <span class="hljs-keyword">extends</span> Error {<br> <span class="hljs-attr">code</span>: <span class="hljs-built_in">number</span>;<br>}<br><span class="hljs-keyword">interface</span> HttpError <span class="hljs-keyword">extends</span> Error {<br> <span class="hljs-attr">statusCode</span>: <span class="hljs-built_in">number</span>;<br>}<br><br><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">isApiError</span>(<span class="hljs-params">error: <span class="hljs-built_in">Error</span></span>) </span>{<br> <span class="hljs-keyword">if</span> (error <span class="hljs-keyword">instanceof</span> ApiError) {<br> <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;<br> }<br> <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;<br>}<br><br><span class="hljs-comment">// index.ts:9:26 - error TS2693: 'ApiError' only refers to a type, but is being used as a value here.</span><br></code></pre></td></tr></table></figure>
<p>需要学习巩固一下: <a href="https://zh.javascript.info/class-inheritance">类与继承</a>。</p>
<h4 id="将任何一个类型断言为any类型"><a href="#将任何一个类型断言为any类型" class="headerlink" title="将任何一个类型断言为any类型"></a>将任何一个类型断言为any类型</h4><p>在 any 类型的变量上,访问任何属性都是允许的。</p>
<p>需要注意的是,将一个变量断言为 any 可以说是解决 TypeScript 中类型问题的最后一个手段。</p>
<p>它极有可能掩盖了真正的类型错误,所以如果不是非常确定,就不要使用 as any。</p>
<p>上面的例子中,我们也可以通过[扩展 window 的类型(TODO)][]解决这个错误,不过如果只是临时的增加 foo 属性,as any 会更加方便。</p>
<p>总之,一方面不能滥用 as any,另一方面也不要完全否定它的作用,我们需要在类型的严格性和开发的便利性之间掌握平衡(这也是 TypeScript 的设计理念之一),才能发挥出 TypeScript 最大的价值。</p>
<h4 id="将-any-断言为一个具体的类型"><a href="#将-any-断言为一个具体的类型" class="headerlink" title="将 any 断言为一个具体的类型"></a>将 any 断言为一个具体的类型</h4><p> 在日常的开发中,我们不可避免的需要处理 any 类型的变量,它们可能是由于第三方库未能定义好自己的类型,也有可能是历史遗留的或其他人编写的烂代码,还可能是受到 TypeScript 类型系统的限制而无法精确定义类型的场景。</p>
<p>遇到 any 类型的变量时,我们可以选择无视它,任由它滋生更多的 any。</p>
<p>我们也可以选择改进它,通过类型断言及时的把 any 断言为精确的类型,亡羊补牢,使我们的代码向着高可维护性的目标发展。</p>
<figure class="highlight typescript"><table><tr><td class="code"><pre><code class="hljs typescript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getCacheData</span>(<span class="hljs-params">key: <span class="hljs-built_in">string</span></span>): <span class="hljs-title">any</span> </span>{<br> <span class="hljs-keyword">return</span> (<span class="hljs-built_in">window</span> <span class="hljs-keyword">as</span> <span class="hljs-built_in">any</span>).cache[key];<br>}<br><br><span class="hljs-keyword">interface</span> Cat {<br> <span class="hljs-attr">name</span>: <span class="hljs-built_in">string</span>;<br> run(): <span class="hljs-built_in">void</span>;<br>}<br><br><span class="hljs-keyword">const</span> tom = getCacheData(<span class="hljs-string">'tom'</span>) <span class="hljs-keyword">as</span> Cat;<br>tom.run();<br></code></pre></td></tr></table></figure>
<p>上面的例子,这个函数调用完后的类型为any,我们可以采用接口的方式将它断言为具体的cat类型,后续对参数的访问就会有相应的代码补全了,能够提高代码的可维护性。</p>
<p><a href="http://ts.xcatliu.com/basics/type-assertion.html#%E5%B0%86-any-%E6%96%AD%E8%A8%80%E4%B8%BA%E4%B8%80%E4%B8%AA%E5%85%B7%E4%BD%93%E7%9A%84%E7%B1%BB%E5%9E%8B">后续参考链接:类型断言、类型转换、类型声明、泛型</a></p>
<h2 id="泛型(generics)"><a href="#泛型(generics)" class="headerlink" title="泛型(generics)"></a>泛型(generics)</h2><p>泛型(Generics)是指在定义函数、接口或类的时候,不预先指定具体的类型,而在使用的时候再指定类型的一种特性。</p>
]]></content>
<categories>
<category>TypeScript</category>
</categories>
<tags>
<tag>TypeScript</tag>
</tags>
</entry>
<entry>
<title>VUE2.X学习</title>
<url>/2021/04/24/uncategorized/6eb6cb2ab58d/</url>
<content><![CDATA[<h1 id="vue2-x教程学习"><a href="#vue2-x教程学习" class="headerlink" title="vue2.x教程学习"></a>vue2.x教程学习</h1><h2 id="安装"><a href="#安装" class="headerlink" title="安装"></a>安装</h2><h3 id="兼容性"><a href="#兼容性" class="headerlink" title="兼容性"></a>兼容性</h3><p>Vue <strong>不支持</strong> IE8 及以下版本,因为 Vue 使用了 IE8 无法模拟的 ECMAScript 5 特性。但它支持所有<a href="https://caniuse.com/#feat=es5">兼容 ECMAScript 5 的浏览器</a>。</p>
<h3 id="语义化版本控制"><a href="#语义化版本控制" class="headerlink" title="语义化版本控制"></a>语义化版本控制</h3><p>Vue 在其所有项目中公布的功能和行为都遵循<a href="https://semver.org/lang/zh-CN/">语义化版本控制</a>。对于未公布的或内部暴露的行为,其变更会描述在<a href="https://github.com/vuejs/vue/releases">发布说明</a>中。</p>
<h3 id="更新日志"><a href="#更新日志" class="headerlink" title="更新日志"></a>更新日志</h3><p>最新稳定版本:2.6.12<br>每个版本的更新日志见 <a href="https://github.com/vuejs/vue/releases">GitHub</a>。</p>
<span id="more"></span>
<h3 id="Vue-Devtools"><a href="#Vue-Devtools" class="headerlink" title="Vue Devtools"></a>Vue Devtools</h3><ul>
<li>在使用 Vue 时,我们推荐在你的浏览器上安装 <a href="https://github.com/vuejs/vue-devtools#vue-devtools">Vue Devtools</a>。它允许你在一个更友好的界面中审查和调试 Vue 应用。</li>
<li> 在Chrome浏览器中可以直接到Chrome网上商店搜索下载</li>
<li> 在edge浏览器中可以打开 <a href="https://chrome.google.com/webstore/category/extensions">Chrome 扩展商店</a>,在搜索栏搜索 <strong>vue.js devtools</strong><br>选择提供方为:<a href="https://vuejs.org/">https://vuejs.org</a> 的扩展,添加成功后,进入扩展设置页面,找到 Vue.js devtools 扩展,点击详细信息,勾选允许访问文件 URL和收集错误选项.<br><img src="https://gitee.com/mhist/hexo-image/raw/master/img/VueDevToolSet-20210424164242.png" alt="vue.js devtools"><h3 id="直接用script标签引用"><a href="#直接用script标签引用" class="headerlink" title="直接用script标签引用"></a>直接用script标签引用</h3>直接下载并用 script 标签引入,Vue会被注册为全局变量。</li>
<li>在开发环境下不要使用压缩版本,不然会失去所有常见错误的相关警告。</li>
<li><a href="https://cn.vuejs.org/js/vue.js">开发版本</a>包含完整的警告和调试模式</li>
<li><a href="https://cn.vuejs.org/js/vue.min.js">压缩版本/生产版本</a>删除了警告,33.30KB min+gzip<h4 id="CDN"><a href="#CDN" class="headerlink" title="CDN"></a>CDN</h4>对于制作原型或学习,你可以这样使用最新版本:<figure class="highlight applescript"><table><tr><td class="code"><pre><code class="hljs applescript"><<span class="hljs-keyword">script</span> src=<span class="hljs-string">"https://cdn.jsdelivr.net/npm/vue/dist/vue.js"</span>><span class="hljs-keyword">script</span>><br></code></pre></td></tr></table></figure>
对于生产环境,我们推荐链接到一个明确的版本号和构建文件,以避免新版本造成的不可预期的破坏:<figure class="highlight applescript"><table><tr><td class="code"><pre><code class="hljs applescript"><<span class="hljs-keyword">script</span> src=<span class="hljs-string">"https://cdn.jsdelivr.net/npm/vue@2.6.12"</span>><span class="hljs-keyword">script</span>><br></code></pre></td></tr></table></figure>
如果你使用原生 ES Modules,这里也有一个兼容 ES Module 的构建文件:<figure class="highlight xml"><table><tr><td class="code"><pre><code class="hljs xml"><span class="hljs-tag"><<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"module"</span>></span><span class="javascript"> <span class="hljs-keyword">import</span> Vue <span class="hljs-keyword">from</span> <span class="hljs-string">'https://cdn.jsdelivr.net/npm/vue@2.6.12/dist/vue.esm.browser.js'</span> script></span><br></code></pre></td></tr></table></figure></li>
</ul>
<p>你可以在 <a href="https://cdn.jsdelivr.net/npm/vue/">cdn.jsdelivr.net/npm/vue</a> 浏览 NPM 包的源代码。</p>
<p>Vue 也可以在 <a href="https://unpkg.com/vue@2.6.12/dist/vue.js">unpkg</a> 和 <a href="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.12/vue.js">cdnjs</a> 上获取 (cdnjs 的版本更新可能略滞后)。</p>
<p>请确认了解<a href="https://cn.vuejs.org/v2/guide/installation.html#%E5%AF%B9%E4%B8%8D%E5%90%8C%E6%9E%84%E5%BB%BA%E7%89%88%E6%9C%AC%E7%9A%84%E8%A7%A3%E9%87%8A">不同构建版本</a>并在你发布的站点中使用<strong>生产环境版本</strong>,把 <code>vue.js</code> 换成 <code>vue.min.js</code>。这是一个更小的构建,可以带来比开发环境下更快的速度体验。</p>
<h3 id="NPM"><a href="#NPM" class="headerlink" title="NPM"></a>NPM</h3><p>在用 Vue 构建大型应用时推荐使用 NPM 安装<a href="https://cn.vuejs.org/v2/guide/installation.html#footnote-1">[1]</a>。NPM 能很好地和诸如 <a href="https://webpack.js.org/">webpack</a> 或 <a href="http://browserify.org/">Browserify</a> 模块打包器配合使用。同时 Vue 也提供配套工具来开发<a href="https://cn.vuejs.org/v2/guide/single-file-components.html">单文件组件</a>。</p>
<figure class="highlight cmake"><table><tr><td class="code"><pre><code class="hljs cmake"><span class="hljs-comment"># 最新稳定版</span><br>$ npm <span class="hljs-keyword">install</span> vue<br></code></pre></td></tr></table></figure>
<h2 id="命令行工具-CLI"><a href="#命令行工具-CLI" class="headerlink" title="命令行工具 (CLI)"></a><a href="https://cli.vuejs.org/zh/">命令行工具 (CLI)</a></h2><p>Vue CLI 是一个基于 Vue.js 进行快速开发的完整系统,提供:</p>
<p>通过 @vue/cli 实现的交互式的项目脚手架。<br>通过 @vue/cli + @vue/cli-service-global 实现的零配置原型开发。<br>一个运行时依赖 (@vue/cli-service),该依赖:<br>可升级;<br>基于 webpack 构建,并带有合理的默认配置;<br>可以通过项目内的配置文件进行配置;<br>可以通过插件进行扩展。<br>一个丰富的官方插件集合,集成了前端生态中最好的工具。<br>一套完全图形化的创建和管理 Vue.js 项目的用户界面。<br>Vue CLI 致力于将 Vue 生态中的工具基础标准化。它确保了各种构建工具能够基于智能的默认配置即可平稳衔接,这样你可以专注在撰写应用上,而不必花好几天去纠结配置的问题。与此同时,它也为每个工具提供了调整配置的灵活性,无需 eject。</p>
]]></content>
<tags>
<tag>vue</tag>
</tags>
</entry>
<entry>
<title>Hello World</title>
<url>/2024/01/22/hexo/435244c26d39/</url>
<content><![CDATA[<p>Welcome to <a href="https://hexo.io/">Hexo</a>! This is your very first post. Check <a href="https://hexo.io/docs/">documentation</a> for more info. If you get any problems when using Hexo, you can find the answer in <a href="https://hexo.io/docs/troubleshooting.html">troubleshooting</a> or you can ask me on <a href="https://github.com/hexojs/hexo/issues">GitHub</a>.</p>
<h2 id="Quick-Start"><a href="#Quick-Start" class="headerlink" title="Quick Start"></a>Quick Start</h2><span id="more"></span>
<h3 id="Create-a-new-post"><a href="#Create-a-new-post" class="headerlink" title="Create a new post"></a>Create a new post</h3><figure class="highlight bash"><table><tr><td class="code"><pre><code class="hljs bash">$ hexo new <span class="hljs-string">"My New Post"</span><br></code></pre></td></tr></table></figure>
<p>More info: <a href="https://hexo.io/docs/writing.html">Writing</a></p>
<h3 id="Run-server"><a href="#Run-server" class="headerlink" title="Run server"></a>Run server</h3><figure class="highlight bash"><table><tr><td class="code"><pre><code class="hljs bash">$ hexo server<br></code></pre></td></tr></table></figure>
<p>More info: <a href="https://hexo.io/docs/server.html">Server</a></p>
<h3 id="Generate-static-files"><a href="#Generate-static-files" class="headerlink" title="Generate static files"></a>Generate static files</h3><figure class="highlight bash"><table><tr><td class="code"><pre><code class="hljs bash">$ hexo generate<br></code></pre></td></tr></table></figure>
<p>More info: <a href="https://hexo.io/docs/generating.html">Generating</a></p>
<h3 id="Deploy-to-remote-sites"><a href="#Deploy-to-remote-sites" class="headerlink" title="Deploy to remote sites"></a>Deploy to remote sites</h3><figure class="highlight bash"><table><tr><td class="code"><pre><code class="hljs bash">$ hexo deploy<br></code></pre></td></tr></table></figure>
<p>More info: <a href="https://hexo.io/docs/one-command-deployment.html">Deployment</a></p>
]]></content>
<categories>
<category>hexo</category>
</categories>
<tags>
<tag>hexo</tag>
</tags>
</entry>
<entry>
<title>git</title>
<url>/2021/11/01/git/0e5e66b4b6b0/</url>
<content><![CDATA[<h2 id="git是什么?"><a href="#git是什么?" class="headerlink" title="git是什么?"></a>git是什么?</h2><p> Git是一种分布式的版本控制软件, 它像是把数据看作是对小型文件系统的一系列快照。 在 Git 中,每当你提交更新或保存项目状态时,它基本上就会对当时的全部文件创建一个快照并保存这个快照的索引。 为了效率,如果文件没有修改,Git 不再重新存储该文件,而是只保留一个链接指向之前存储的文件。 Git 对待数据更像是一个 <font color=amber>快照流</font>。</p>
<h2 id="git的特点"><a href="#git的特点" class="headerlink" title="git的特点"></a>git的特点</h2><ol>
<li>直接记录快照,而非差异比较</li>
<li>近乎所有操作都是本地执行</li>
<li>Git 保证完整性 (Git 数据库中保存的信息都是以文件内容的哈希值来索引,而不是文件名。)</li>
<li>Git 一般只添加数据</li>
</ol>
<div class="note default modern"><p> Git 用以计算校验和的机制叫做 SHA-1 散列(hash,哈希)。 这是一个由 40 个十六进制字符(0-9 和 a-f)组成的字符串,基于 Git 中文件的内容或目录结构计算出来。 SHA-1 哈希看起来是这样:</p>
<figure class="highlight dns"><table><tr><td class="code"><pre><code class="hljs dns"><span class="hljs-number">24</span>b9da6552252987aa493b52f8696cd<span class="hljs-number">6d3b00373</span><br></code></pre></td></tr></table></figure></div>
<h2 id="git的三种区域划分"><a href="#git的三种区域划分" class="headerlink" title="git的三种区域划分"></a>git的三种区域划分</h2><ul>
<li><p> 已修改(modified):表示修改了文件,但还没保存到数据库中。</p>
</li>
<li><p>已暂存(staged): 表示对一个已修改文件的当前版本做了标记,使之包含在下次提交的快照中。</p>
</li>
<li><p>已提交(committed):表示数据已经安全地保存在本地数据库中。</p>
</li>
</ul>
<p><img src="https://git-scm.com/book/en/v2/images/areas.png" alt="git三种区域"></p>
<h2 id="初次运行-Git-前的配置"><a href="#初次运行-Git-前的配置" class="headerlink" title="初次运行 Git 前的配置"></a>初次运行 Git 前的配置</h2><h3 id="用户信息"><a href="#用户信息" class="headerlink" title="用户信息"></a>用户信息</h3><p>安装完 Git 之后,要做的第一件事就是设置你的用户名和邮件地址。 这一点很重要,因为每一个 Git 提交都会使用这些信息,它们会写入到你的每一次提交中,不可更改:</p>
<figure class="highlight verilog"><table><tr><td class="code"><pre><code class="hljs verilog">git <span class="hljs-keyword">config</span> --<span class="hljs-keyword">global</span> user<span class="hljs-variable">.name</span> <span class="hljs-string">"John Doe"</span><br>git <span class="hljs-keyword">config</span> --<span class="hljs-keyword">global</span> user<span class="hljs-variable">.email</span> johndoe@example<span class="hljs-variable">.com</span><br></code></pre></td></tr></table></figure>
<div class="note default modern"><p>再次强调,如果使用了 –global 选项,那么该命令只需要运行一次,因为之后无论你在该系统上做任何事情, Git 都会使用那些信息。 当你想针对特定项目使用不同的用户名称与邮件地址时,可以在那个项目目录下运行没有 –global 选项的命令来配置。</p>
</div>
<h3 id="文本编辑器"><a href="#文本编辑器" class="headerlink" title="文本编辑器"></a>文本编辑器</h3><p>在 Windows 系统上,如果你想要使用别的文本编辑器,那么必须指定可执行文件的完整路径。 它可能随你的编辑器的打包方式而不同。</p>
<figure class="highlight brainfuck"><table><tr><td class="code"><pre><code class="hljs brainfuck"><span class="hljs-comment">git</span> <span class="hljs-comment">config</span> --<span class="hljs-comment">global</span> <span class="hljs-comment">core</span><span class="hljs-string">.</span><span class="hljs-comment">editor</span> <span class="hljs-comment">"'C:/Program</span> <span class="hljs-comment">Files/Notepad</span>++<span class="hljs-comment">/notepad</span>++<span class="hljs-string">.</span><span class="hljs-comment">exe'</span> <span class="hljs-literal">-</span><span class="hljs-comment">multiInst</span> <span class="hljs-literal">-</span><span class="hljs-comment">notabbar</span> <span class="hljs-literal">-</span><span class="hljs-comment">nosession</span> <span class="hljs-literal">-</span><span class="hljs-comment">noPlugin"</span><br></code></pre></td></tr></table></figure>
<h3 id="检查配置信息"><a href="#检查配置信息" class="headerlink" title="检查配置信息"></a>检查配置信息</h3><figure class="highlight lua"><table><tr><td class="code"><pre><code class="hljs lua">git <span class="hljs-built_in">config</span> <span class="hljs-comment">--list</span><br></code></pre></td></tr></table></figure>
<pre>
PS C:\Users\starry\Desktop\hexo-new> git config --list
diff.astextplain.textconv=astextplain
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
http.sslbackend=openssl
http.sslcainfo=D:/dev/git/Git/mingw64/ssl/certs/ca-bundle.crt
core.autocrlf=true
core.fscache=true
core.symlinks=false
pull.rebase=false
credential.helper=manager-core
credential.https://dev.azure.com.usehttppath=true
:...skipping...
diff.astextplain.textconv=astextplain
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
http.sslbackend=openssl
http.sslcainfo=D:/dev/git/Git/mingw64/ssl/certs/ca-bundle.crt
core.autocrlf=true
core.fscache=true
core.symlinks=false
pull.rebase=false
credential.helper=manager-core
credential.https://dev.azure.com.usehttppath=true
init.defaultbranch=master
core.editor="D:\dev\vscode\Microsoft VS Code\bin\code.cmd" --wait
user.email=18827637106@163.com
user.name=mhist
http.sslverify=false
http.postbuffer=524288000
</pre>
<p>使用该命令后,你会获得如上的键值对形式的文件,当然你也可以使用命令,通过键来获得你需要得键值</p>
<figure class="highlight arduino"><table><tr><td class="code"><pre><code class="hljs arduino">git config <key><br></code></pre></td></tr></table></figure>
<pre>
PS C:\Users\starry\Desktop\hexo-new> git config core.fscache
true
</pre>
<h2 id="获取帮助和官方手册"><a href="#获取帮助和官方手册" class="headerlink" title="获取帮助和官方手册"></a>获取帮助和官方手册</h2><figure class="highlight arduino"><table><tr><td class="code"><pre><code class="hljs arduino">git help config<br></code></pre></td></tr></table></figure>
<p>输入命令后会在浏览器打开手册,通过html文件来展示。实际在安装git软件的时候会在相应的文件夹中,博主的文件对应路径为:</p>
<figure class="highlight awk"><table><tr><td class="code"><pre><code class="hljs awk">file:<span class="hljs-regexp">//</span><span class="hljs-regexp">/D:/</span>dev<span class="hljs-regexp">/git/</span>Git<span class="hljs-regexp">/mingw64/</span>share<span class="hljs-regexp">/doc/gi</span>t-doc/git-config.html<br></code></pre></td></tr></table></figure>
<h2 id="常用命令"><a href="#常用命令" class="headerlink" title="常用命令"></a>常用命令</h2><table>
<thead>
<tr>
<th align="center">命令</th>
<th align="center">效果</th>
<th align="center">场景</th>
</tr>
</thead>
<tbody><tr>
<td align="center">git clone url</td>
<td align="center">在本地创建相应的仓库</td>
<td align="center">用于克隆目标链接的文件</td>
</tr>
<tr>
<td align="center">git init</td>
<td align="center">在已存在目录中初始化仓库</td>
<td align="center">用于初始化</td>
</tr>
<tr>
<td align="center">git status</td>
<td align="center">显示文件分支和文件提交情况和工作区情况</td>
<td align="center">用于检测当前仓库文件状态</td>
</tr>
<tr>
<td align="center">git add</td>
<td align="center">使用文件或目录的路径作为参数,目录路径下所有文件会被追踪</td>
<td align="center">用于跟踪新文件,将文件放到暂存区</td>
</tr>
<tr>
<td align="center">git diff</td>
<td align="center">本身只显示尚未暂存的改动,而不是自上次提交以来所做的所有改动</td>
<td align="center">用于查看已暂存和未暂存的修改</td>
</tr>
<tr>
<td align="center">git commit</td>
<td align="center">将暂存区的文件提交,可通过<font color=camel>git commit -m “添加描述信息”</font></td>
<td align="center">用于提交更新</td>
</tr>
<tr>
<td align="center">git rm</td>
<td align="center">若文件不在暂存区 <font color=tomato>git rm 文件名 </font>;否则,使用<font color=camel>git rm -f 文件名</font></td>
<td align="center">用于移除文件,<a href="https://git-scm.com/book/zh/v2/Git-%E5%9F%BA%E7%A1%80-%E8%AE%B0%E5%BD%95%E6%AF%8F%E6%AC%A1%E6%9B%B4%E6%96%B0%E5%88%B0%E4%BB%93%E5%BA%93">其他删除细节参照链接</a></td>
</tr>
<tr>
<td align="center">git mv 原文件名 新文件名</td>
<td align="center">实质:<code>mv README.md README;git rm README.md;git add README</code></td>
<td align="center">用于移动文件或者修改文件名</td>
</tr>
<tr>
<td align="center">git log</td>
<td align="center">在控制台输入命令后会显示以哈希值版本,作者,提交时间组成的内容</td>
<td align="center">用于查看提交历史</td>
</tr>
</tbody></table>
<div class="note default modern"><p>如果文件已被跟踪,然后再后续过程中被修改,则该跟踪文件的内容发生了变化,但还没有放到暂存区。 要暂存这次更新,需要运行 git add 命令。 这是个多功能命令:可以用它开始跟踪新文件,或者把已跟踪的文件放到暂存区,还能用于合并时把有冲突的文件标记为已解决状态等。 将这个命令理解为“精确地将内容添加到下一次提交中”</p>
</div>
<h3 id="git-log-配置"><a href="#git-log-配置" class="headerlink" title="git log 配置"></a>git log 配置</h3><p><a href="https://git-scm.com/book/zh/v2/Git-%E5%9F%BA%E7%A1%80-%E6%9F%A5%E7%9C%8B%E6%8F%90%E4%BA%A4%E5%8E%86%E5%8F%B2">配置例子具体链接</a></p>
<p>例子:将提交版本的哈希值用简短形式展示</p>
<pre>
PS C:\Users\starry\Desktop\hexo-new\blog> git log --pretty=format:"%h"
0f2dda8
40f740a
668fc87
2b7da17
418255c
7601831
f89d8a5
</pre>
<h3 id="撤销操作"><a href="#撤销操作" class="headerlink" title="撤销操作"></a>撤销操作</h3><ol>
<li><p>它一般用于解决在开发过程中因为细微的操作导致的问题,比如在提交完成后发现有些文件忘记更新到缓存区,导致文件没有提交,而文件又不是很多,如果再次提交,会增多提交历史中的事件轴,为了解决这一问题可以使用以下命令,它会提交第二次的修改,从效果上来说,就像是旧有的提交从未存在过一样,它并不会出现在仓库的历史中。</p>
<figure class="highlight pgsql"><table><tr><td class="code"><pre><code class="hljs pgsql">git <span class="hljs-keyword">commit</span> <span class="hljs-comment">--amend</span><br></code></pre></td></tr></table></figure></li>
<li><p>取消暂存</p>
<figure class="highlight sas"><table><tr><td class="code"><pre><code class="hljs sas">git <span class="hljs-meta">reset</span> HEAD <<span class="hljs-meta">file</span>>...<br></code></pre></td></tr></table></figure></li>
</ol>
<h2 id="远程仓库"><a href="#远程仓库" class="headerlink" title="远程仓库"></a>远程仓库</h2><h3 id="查看远程仓库"><a href="#查看远程仓库" class="headerlink" title="查看远程仓库"></a>查看远程仓库</h3><figure class="highlight ebnf"><table><tr><td class="code"><pre><code class="hljs ebnf"><span class="hljs-attribute">git remote</span><br></code></pre></td></tr></table></figure>
<figure class="highlight ebnf"><table><tr><td class="code"><pre><code class="hljs ebnf"><span class="hljs-attribute">git remote -v</span><br></code></pre></td></tr></table></figure>
<h3 id="添加远程仓库"><a href="#添加远程仓库" class="headerlink" title="添加远程仓库"></a>添加远程仓库</h3><figure class="highlight vim"><table><tr><td class="code"><pre><code class="hljs vim">git remote <span class="hljs-built_in">add</span> <span class="hljs-symbol"><shortname></span> <span class="hljs-symbol"><url></span><br></code></pre></td></tr></table></figure>
<h3 id="从远程仓库拉取"><a href="#从远程仓库拉取" class="headerlink" title="从远程仓库拉取"></a>从远程仓库拉取</h3><figure class="highlight xml"><table><tr><td class="code"><pre><code class="hljs xml">git fetch <span class="hljs-tag"><<span class="hljs-name">remote</span>></span><br></code></pre></td></tr></table></figure>
<h3 id="推送到远程仓库"><a href="#推送到远程仓库" class="headerlink" title="推送到远程仓库"></a>推送到远程仓库</h3><figure class="highlight maxima"><table><tr><td class="code"><pre><code class="hljs maxima">git <span class="hljs-built_in">push</span> <span class="hljs-built_in">origin</span> master<br></code></pre></td></tr></table></figure>
<h3 id="查看某个远程仓库"><a href="#查看某个远程仓库" class="headerlink" title="查看某个远程仓库"></a>查看某个远程仓库</h3><figure class="highlight xml"><table><tr><td class="code"><pre><code class="hljs xml">git remote show <span class="hljs-tag"><<span class="hljs-name">remote</span>></span> <br></code></pre></td></tr></table></figure>
<h3 id="远程仓库的重命名"><a href="#远程仓库的重命名" class="headerlink" title="远程仓库的重命名"></a>远程仓库的重命名</h3><p>例如,想要将 pb 重命名为 paul,可以用 git remote rename 这样做:</p>
<figure class="highlight coq"><table><tr><td class="code"><pre><code class="hljs coq">git remote <span class="hljs-built_in">rename</span> pb paul<br></code></pre></td></tr></table></figure>
<h3 id="远程仓库的删除"><a href="#远程仓库的删除" class="headerlink" title="远程仓库的删除"></a>远程仓库的删除</h3><figure class="highlight routeros"><table><tr><td class="code"><pre><code class="hljs routeros">git remote <span class="hljs-builtin-name">remove</span> 远程仓库名<br></code></pre></td></tr></table></figure>
<h2 id="git分支与合并"><a href="#git分支与合并" class="headerlink" title="git分支与合并"></a>git分支与合并</h2><ol>
<li><p>查看分支 </p>
<figure class="highlight ebnf"><table><tr><td class="code"><pre><code class="hljs ebnf"><span class="hljs-attribute">git branch</span><br></code></pre></td></tr></table></figure></li>
<li><p>创建分支</p>
<figure class="highlight mipsasm"><table><tr><td class="code"><pre><code class="hljs mipsasm">git <span class="hljs-keyword">branch </span>分支名称<br></code></pre></td></tr></table></figure></li>
<li><p>切换分支</p>
<figure class="highlight nginx"><table><tr><td class="code"><pre><code class="hljs nginx"><span class="hljs-attribute">git</span> checkout 分支名称<br></code></pre></td></tr></table></figure></li>
<li><p>分支合并<br>假设现在有两个分支,分别为master和test分支,当前你在master分支上,可以使用以下命令将test分支上的内容合并到master分支上。</p>
<figure class="highlight stata"><table><tr><td class="code"><pre><code class="hljs stata">git <span class="hljs-keyword">merge</span> <span class="hljs-keyword">test</span><br></code></pre></td></tr></table></figure></li>
</ol>
<p>合并冲突:</p>
<ol start="5">
<li>删除分支<figure class="highlight mipsasm"><table><tr><td class="code"><pre><code class="hljs mipsasm">git <span class="hljs-keyword">branch </span>-d 分支名称<br></code></pre></td></tr></table></figure></li>
</ol>
]]></content>
<categories>
<category>git</category>
</categories>
<tags>
<tag>git</tag>
</tags>
</entry>
<entry>
<title>hexo (mixed-content)</title>
<url>/2024/06/24/hexo/006b45bc9237/</url>
<content><![CDATA[<h1 id="遇到mixed-content"><a href="#遇到mixed-content" class="headerlink" title="遇到mixed-content"></a>遇到mixed-content</h1><p>最新、在学习Java代码的过程中有图片上传的需求、于是开始研究起了MINIO、在存储服务器搭建成功之后、也能够生成浏览器能够直接访问的图片链接、但是在记录博客的时候、想将云存储的图片直接作为图床图片用于markdown文档、 发现被屏蔽了。</p>
<p><img src="https://cdn.jsdelivr.net/gh/mhist/hexoImage@main/img/mixed-content.png" alt="被屏蔽"></p>
<h1 id="问题原因"><a href="#问题原因" class="headerlink" title="问题原因"></a>问题原因</h1><p>经过网络查询、发现是因为协议的不同、导致无法将http协议自动升级为https, 于是发现可以使用</p>
<p>Adding this to your HTML header looks like this:</p>
<figure class="highlight routeros"><table><tr><td class="code"><pre><code class="hljs routeros"><meta <span class="hljs-attribute">http-equiv</span>=<span class="hljs-string">"Content-Security-Policy"</span> <span class="hljs-attribute">content</span>=<span class="hljs-string">"upgrade-insecure-requests"</span> /><br></code></pre></td></tr></table></figure>
<p>内容安全策略(Content-Security-Policy, CSP):这是网页开发中引入的一项关键安全特性,旨在通过为浏览器定义一套关于哪些内容来源可信任的规则,帮助防止跨站脚本(XSS)攻击及其他代码注入攻击。它使网页开发者能够为脚本、样式表、图片和其他资源指定合法的来源。</p>
<p>升级不安全请求(upgrade-insecure-requests):这是内容安全策略头中的一项具体指令。当包含此指令时,它要求浏览器将所有不安全的请求(即使用HTTP的请求)视为通过HTTPS发出的请求。实际上,这意味着只要服务器支持HTTPS,浏览器就会尝试在发起网络请求之前,将请求URL从http://重写为https://。此指令通过减少在整个网站上更新硬编码URL的需求,简化了向HTTPS迁移的过程。</p>
<p>需要注意的是,尽管此指令通过鼓励使用HTTPS来提升安全性,但它本身并不是一个全面的解决方案。一个完整的内容安全策略实施通常还包括明确指定各种类型内容的允许来源。此外,仅依赖于upgrade-insecure-requests可能无法涵盖应用程序资源或脚本中存在显式协议引用的所有情况。因此,在实施此类更改后彻底测试您的网站至关重要,以确保一切如预期般正常运行。</p>
<h1 id="博客配置文件定位"><a href="#博客配置文件定位" class="headerlink" title="博客配置文件定位"></a>博客配置文件定位</h1><p>themes/butterfly/_config.yml</p>
<figure class="highlight routeros"><table><tr><td class="code"><pre><code class="hljs routeros"><span class="hljs-comment"># Inject</span><br><span class="hljs-comment"># Insert the code to head (before '</head>' tag) and the bottom (before '</body>' tag)</span><br><span class="hljs-comment"># 插入代码到头部 </head> 之前 和 底部 </body> 之前</span><br>inject:<br> head:<br> # - <link <span class="hljs-attribute">rel</span>=<span class="hljs-string">"stylesheet"</span> <span class="hljs-attribute">href</span>=<span class="hljs-string">"/xxx.css"</span>><br> <meta <span class="hljs-attribute">http-equiv</span>=<span class="hljs-string">"Content-Security-Policy"</span> <span class="hljs-attribute">content</span>=<span class="hljs-string">"upgrade-insecure-requests"</span> /><br> bottom:<br> # - <script <span class="hljs-attribute">src</span>=<span class="hljs-string">"xxxx"</span>></script><br><br></code></pre></td></tr></table></figure>
<p><img src="https://cdn.jsdelivr.net/gh/mhist/hexoImage@main/img/CSP%20preview.png" alt="加入后的效果"></p>
<h1 id="加入上述但是还是无法访问"><a href="#加入上述但是还是无法访问" class="headerlink" title="加入上述但是还是无法访问"></a>加入上述但是还是无法访问</h1><p>最后是将minio服务升级为https</p>
<p><a href="https://www.elibaron.com/arch/minio/minio-https.html#_3-3-docker%E5%90%AF%E5%8A%A8">参考学习</a></p>
<p><a href="https://min.io/docs/minio/linux/operations/network-encryption.html?ref=docs-redirect#enabling-tls">minio官方文档: tls</a></p>
<p><a href="https://github.com/minio/certgen">A dead simple tool to generate self signed certificates for MinIO TLS deployments</a></p>
<p>使用命令行下载:Linux amd64 (我的环境是Linux系统)</p>
<figure class="highlight awk"><table><tr><td class="code"><pre><code class="hljs awk">wget https:<span class="hljs-regexp">//gi</span>thub.com<span class="hljs-regexp">/minio/</span>certgen<span class="hljs-regexp">/releases/</span>latest<span class="hljs-regexp">/download/</span>certgen-linux-amd64<br></code></pre></td></tr></table></figure>
<p><img src="https://cdn.jsdelivr.net/gh/mhist/hexoImage@main/img/minio-https.png" alt="minio-https"></p>
<p><img src="https://cdn.jsdelivr.net/gh/mhist/hexoImage@main/img/minio-https-api.png" alt="minio-https-api"></p>
]]></content>
<categories>
<category>hexo</category>
</categories>
<tags>
<tag>hexo</tag>
</tags>
</entry>
<entry>
<title>关于开始搭建hexo博客这件事</title>
<url>/2021/04/20/hexo/5fcb7dadb6f9/</url>
<content><![CDATA[<h1 id="hexo个人博客搭建"><a href="#hexo个人博客搭建" class="headerlink" title="hexo个人博客搭建"></a>hexo个人博客搭建</h1><h2 id="为什么会搭建hexo博客"><a href="#为什么会搭建hexo博客" class="headerlink" title="为什么会搭建hexo博客"></a>为什么会搭建hexo博客</h2><p> 原因:<br> 1.用于前端学习记录、且便于复习,因为经过加工一次的比外来搜索的资料来说更容易让大脑快速识别与利用。<br> 2.阿里云轻量级WordPress服务器对非在校生的优惠终止,且个人网站将于2021年5月份到期,这是我的个人WordPress博客链接 <a href="http://www.codetotoro.cn/">www.codetotoro.cn</a>,同时因为服务器类型的缘故,按照提交工单时工作人员的说法,相关的数据迁移是无法进行的,除非是继续续费。<br> 3.部署方便且相关的学习教程更多,且官方的教程及相应的主题教程很全面,同时社区活跃,搭建博客的相关配置包括hexo editor都很容易找到,最重要的是部署方便,且bug很少,即使是使用外置主题,而且配置的修改采用注释/取消注释的方式进行,方便日后修改,而不用每次都需要根据官方文档再去配置,省去了很多麻烦。<br> <span id="more"></span></p>
<h2 id="搭建博客的相关教程"><a href="#搭建博客的相关教程" class="headerlink" title="搭建博客的相关教程"></a>搭建博客的相关教程</h2><h3 id="视频教程"><a href="#视频教程" class="headerlink" title="视频教程"></a>视频教程</h3><p> 来自哔哩哔哩up-codesheep的视频教程,讲解细致全面<br> <a href="https://www.bilibili.com/video/BV1Yb411a7ty/?spm_id_from=333.788.recommend_more_video.0">手把手教你从0开始搭建自己的个人博客 |无坑版视频教程| hexo</a><br> 学习笔记<br> <pre><br> --- #安装Nodejs<br>node -v #查看node版本<br>npm -v #查看npm版本<br>npm install -g cnpm --registry=<a href="http://registry.npm.taobao.org/">http://registry.npm.taobao.org</a> #安装淘宝的cnpm 管理器<br>cnpm -v #查看cnpm版本<br>cnpm install -g hexo-cli #安装hexo框架<br>hexo -v #查看hexo版本<br>mkdir blog #创建blog目录<br>cd blog #进入blog目录<br>sudo hexo init #生成博客 初始化博客<br>hexo s #启动本地博客服务<br><a href="http://localhost:4000/">http://localhost:4000/</a> #本地访问地址<br>hexo n 我的第一篇文章 #创建新的文章<br>#返回blog目录<br>hexo clean #清理<br>hexo g #生成<br>#Github创建一个新的仓库 YourGithubName.github.io<br>#在blog目录下安装git部署插件<br> cnpm install --save hexo-deployer-git </p>
<hr>
<h2 id="配置-config-yml"><a href="#配置-config-yml" class="headerlink" title="#配置_config.yml "></a>#配置_config.yml </h2><pre><code># Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
type: git
repo: https://github.com/YourGithubName/YourGithubName.github.io.git
branch: master
</code></pre>
<hr>
<p>hexo d #部署到Github仓库里<br><a href="https://yourgithubname.github.io/">https://YourGithubName.github.io/</a> #访问这个地址可以查看博客</p>
<p> git clone <a href="https://github.com/litten/hexo-theme-yilia.git">https://github.com/litten/hexo-theme-yilia.git</a> themes/yilia #下载yilia主题到本地</p>
<p>#修改hexo根目录下的 _config.yml 文件 : theme: yilia</p>
<p>hexo c #清理一下<br>hexo g #生成<br>hexo s #启动本地博客服务<br><a href="http://localhost:4000/">http://localhost:4000/</a> #本地访问地址<br>hexo d #部署到远程Github仓库<br><a href="https://yourgithubname.github.io/">https://YourGithubName.github.io/</a> #查看博客<br> </pre></p>
<hr>
<h3 id="官方文档及next主题官方文档"><a href="#官方文档及next主题官方文档" class="headerlink" title="官方文档及next主题官方文档"></a>官方文档及next主题官方文档</h3><p> 1.<a href="https://hexo.io/zh-cn/docs/">hexo文档</a><br> 2.<a href="http://theme-next.iissnan.com/getting-started.html">hexo-next主题文档</a></p>
<h2 id="博客的后续配置"><a href="#博客的后续配置" class="headerlink" title="博客的后续配置"></a>博客的后续配置</h2><p> 博客中有很多可用于拓展的地方,暂时还有很多不太了解,但是可以满足日常的写作需求以及部署,此处用于记录对于配置方面的自己的一些理解。</p>
<h3 id="配置-config-yml,gitee-github简单修改实现双部署"><a href="#配置-config-yml,gitee-github简单修改实现双部署" class="headerlink" title="配置_config.yml,gitee/github简单修改实现双部署"></a>配置_config.yml,gitee/github简单修改实现双部署</h3><pre><code>#配置_config.yml
</code></pre>
<hr>
<pre><code># Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
type: git
repo:
gitee: https://gitee.com/mhist/mhist.git
#https://github.com/Mhist/Mhist.github.io.git
#github
branch: master
</code></pre>
<p>—–以上代码是我在实践过程中发现的一点,因为在github上是可以做到自动部署的,可是因为防火墙的原因导致访问经常失败,而gitee作为国内的github,访问速度是很快的,只是部署的时候需要手动更新,因为自动更新部署是要收费的。<br> 以上代码的使用方式是在repo中:<br> 1.部署到gitee时,按照hexo c; hexo g; hexo s; hexo d,然后到码云的位置点击更新即可。<img src="https://gitee.com/mhist/hexo-image/raw/master/img/20210421013409-giteePagesUpdateButton.png" alt="gitee pages update button">,然后可访问域名:<a href="https://mhist.gitee.io/">https://mhist.gitee.io/</a><br> 2.部署到github时,将gitee所在行用#注释掉即可,同时取消gitee下一行的#注释,按照hexo c; hexo g; hexo s; hexo d即可。然后可访问域名:<a href="https://mhist.github.io/">https://mhist.github.io/</a></p>
<h2 id="图床的设置"><a href="#图床的设置" class="headerlink" title="图床的设置"></a>图床的设置</h2><p> 作为使用Markdown来编辑文档的人来说,拥有一个好的图床是非常必要的。通过图床我们可以很好的管理我们的博客图片,同时能在多方正确显示。</p>
<h3 id="图床分类"><a href="#图床分类" class="headerlink" title="图床分类"></a>图床分类</h3><p> 现在比较流行的图床有很多,包括SM.MS图床、腾讯云cos、github图床、七牛云图床、Imgur图床、阿里云COS、又拍云图床、gitee。但同时具有安全、经济、使用方便、访问高速等多种优点的解决方案还是要数基于picgo+gitee的解决方案.</p>
<h3 id="picgo"><a href="#picgo" class="headerlink" title="picgo"></a>picgo</h3><p> picgo是一款基于桌面端图床工具,方便我们对接本地和远程仓库,同时快速获取链接,同时支持链接的Markdown、HTML、URL、UBB、Custom等五种格式的选择,同时可以支持插件以丰富软件功能。<br> 推荐两个配置教程:</p>
<ol>
<li><a href="https://blog.csdn.net/disILLL/article/details/103962241?utm_medium=distribute.pc_relevant_t0.none-task-blog-2~default~BlogCommendFromMachineLearnPai2~default-1.control&dist_request_id=1332024.918.16189409573562535&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-2~default~BlogCommendFromMachineLearnPai2~default-1.control">配置教程1</a></li>
<li><a href="https://zhuanlan.zhihu.com/p/128014135">配置教程2—插件</a></li>
<li><a href="https://github.com/Molunerfinn/PicGo/releases">picgo的github链接</a></li>
<li>picgo Windows <a href="https://pan.baidu.com/s/1y_yn9dl5aEAGHBX2c2KDPA">PicGo-Setup-2.3.0-beta.5.exe</a> 提取码:hexo</li>
</ol>
<h1 id="处理"><a href="#处理" class="headerlink" title="处理"></a>处理</h1>]]></content>
<categories>
<category>hexo</category>
</categories>
<tags>
<tag>hexo</tag>
</tags>
</entry>
<entry>
<title>hexo样式修改汇总</title>
<url>/2021/09/28/hexo/371af6f33ab0/</url>
<content><![CDATA[<h1 id="hexo样式汇总"><a href="#hexo样式汇总" class="headerlink" title="hexo样式汇总"></a>hexo样式汇总</h1><h1 id="更改超链接格式(文字颜色)"><a href="#更改超链接格式(文字颜色)" class="headerlink" title="更改超链接格式(文字颜色)"></a>更改超链接格式(文字颜色)</h1><div class="note primary modern"><p><a href="https://vonsdite.github.io/posts/13afd8d4.html">参考链接:Von</a> </p>
</div>
<h2 id="插图编号-醒目文字"><a href="#插图编号-醒目文字" class="headerlink" title="插图编号| 醒目文字"></a>插图编号| 醒目文字</h2><figure class="highlight django"><table><tr><td class="code"><pre><code class="hljs django"><span class="xml"></span><br><span class="xml"></span><span class="hljs-template-tag">{% <span class="hljs-name">note</span> default %}</span><span class="xml"> 默认样式 </span><span class="hljs-template-tag">{% <span class="hljs-name">endnote</span> %}</span><span class="xml"></span><br><span class="xml"></span><span class="hljs-template-tag">{% <span class="hljs-name">note</span> primary %}</span><span class="xml"> 主要样式 </span><span class="hljs-template-tag">{% <span class="hljs-name">endnote</span> %}</span><span class="xml"></span><br><span class="xml"></span><span class="hljs-template-tag">{% <span class="hljs-name">note</span> success %}</span><span class="xml"> 成功样式 </span><span class="hljs-template-tag">{% <span class="hljs-name">endnote</span> %}</span><span class="xml"></span><br><span class="xml"></span><span class="hljs-template-tag">{% <span class="hljs-name">note</span> info %}</span><span class="xml"> 信息样式 </span><span class="hljs-template-tag">{% <span class="hljs-name">endnote</span> %}</span><span class="xml"></span><br><span class="xml"></span><span class="hljs-template-tag">{% <span class="hljs-name">note</span> warning %}</span><span class="xml"> 警告样式 </span><span class="hljs-template-tag">{% <span class="hljs-name">endnote</span> %}</span><span class="xml"></span><br><span class="xml"></span><span class="hljs-template-tag">{% <span class="hljs-name">note</span> danger %}</span><span class="xml"> 危险样式 </span><span class="hljs-template-tag">{% <span class="hljs-name">endnote</span> %}</span><span class="xml"></span><br><span class="xml"></span><br><span class="xml"></span><br></code></pre></td></tr></table></figure>
<div class="note default modern"><p>默认样式 </p>
</div>
<div class="note primary modern"><p>主要样式 </p>
</div>
<div class="note success modern"><p>成功样式 </p>
</div>
<div class="note info modern"><p>信息样式 </p>
</div>
<div class="note warning modern"><p>警告样式 </p>
</div>
<div class="note danger modern"><p>危险样式 </p>
</div>
<h2 id="使用选项卡"><a href="#使用选项卡" class="headerlink" title="使用选项卡"></a>使用选项卡</h2><figure class="highlight django"><table><tr><td class="code"><pre><code class="hljs django"><span class="hljs-template-tag">{% <span class="hljs-name">tabs</span> tab,1 %}</span><span class="xml"> 名字为tab,默认在第1个选项卡,如果是-1则隐藏</span><br><span class="xml"><span class="hljs-comment"><!-- tab --></span></span><br><span class="xml">**选项卡 1** </span><br><span class="xml"><span class="hljs-comment"><!-- endtab --></span></span><br><span class="xml"><span class="hljs-comment"><!-- tab --></span></span><br><span class="xml">**选项卡 2**</span><br><span class="xml"><span class="hljs-comment"><!-- endtab --></span></span><br><span class="xml"><span class="hljs-comment"><!-- tab A --></span></span><br><span class="xml">**选项卡 3** 名字为A</span><br><span class="xml"><span class="hljs-comment"><!-- endtab --></span></span><br><span class="xml"></span><span class="hljs-template-tag">{% <span class="hljs-name">endtabs</span> %}</span><br></code></pre></td></tr></table></figure>
<p>效果展示:</p>
<div class="tabs" id="tab"><ul class="nav-tabs"><li class="tab active"><button type="button" data-href="#tab-1">tab 1</button></li><li class="tab"><button type="button" data-href="#tab-2">tab 2</button></li><li class="tab"><button type="button" data-href="#tab-3">A</button></li></ul><div class="tab-contents"><div class="tab-item-content active" id="tab-1"><p><strong>选项卡 1</strong> </p><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="tab-2"><p><strong>选项卡 2</strong></p><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="tab-3"><p><strong>选项卡 3</strong> 名字为A</p><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div></div></div>
<h2 id="自动生成目录(hexo-toc)"><a href="#自动生成目录(hexo-toc)" class="headerlink" title="自动生成目录(hexo-toc)"></a>自动生成目录(hexo-toc)</h2><p> 主题自带的配置项,生成的目录是不能够点击到文章目录自动滑动到页面指定位置的。<br> <figure class="highlight yaml"><table><tr><td class="code"><pre><code class="hljs yaml"><span class="hljs-comment"># Table Of Contents in the Sidebar</span><br><span class="hljs-attr">toc:</span><br> <span class="hljs-attr">enable:</span> <span class="hljs-literal">false</span><br><br> <span class="hljs-comment"># Automatically add list number to toc.</span><br> <span class="hljs-attr">number:</span> <span class="hljs-literal">true</span><br><br> <span class="hljs-comment"># If true, all words will placed on next lines if header width longer then sidebar width.</span><br> <span class="hljs-attr">wrap:</span> <span class="hljs-literal">false</span><br></code></pre></td></tr></table></figure><br> 通过hexo-toc生成的目录可以实现点击调转到指定页面位置,同时可以支持目录级别选择。</p>
<div class="note danger modern"><p><a href="https://www.dazhuanlan.com/bassd/topics/1055823">参考链接:hexo-toc,但是此链接还是无法解决目录的生成问题</a> </p>
</div>
<p>所以,重点是解决hexo-next主题自带的toc目录,锚点失效的原因:</p>
<div class="note success modern"><p><a href="https://blog.csdn.net/qq_42009500/article/details/116129303?utm_medium=distribute.pc_relevant.none-task-blog-2~default~OPENSEARCH~default-8.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2~default~OPENSEARCH~default-8.no_search_link">参考链接:hexo-toc锚点失效—有效解决办法</a> </p>
</div>
<p><img src="https://cdn.jsdelivr.net/gh/mhist/hexoImage@main/img/20210928152335tocPostDetails.png" alt="目录锚点失效的原因"></p>
<p>报错文件路径: <font color=chocolate>themes/next/source/js/post-details.js</font></p>
<figure class="highlight reasonml"><table><tr><td class="code"><pre><code class="hljs reasonml"><span class="hljs-comment">// TOC item animation navigate & prevent #item selector in adress bar.</span><br> <span class="hljs-constructor">$('.<span class="hljs-params">post</span>-<span class="hljs-params">toc</span> <span class="hljs-params">a</span>')</span>.on('click', <span class="hljs-keyword">function</span> (e) {<br> e.prevent<span class="hljs-constructor">Default()</span>;<br> var targetSelector = <span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">NexT</span>.</span></span>utils.escape<span class="hljs-constructor">Selector(<span class="hljs-params">this</span>.<span class="hljs-params">getAttribute</span>('<span class="hljs-params">href</span>')</span>);<br><br> <!-- 添加下面这行代码, 重新解析 URL -><br> targetSelector = decode<span class="hljs-constructor">URI(<span class="hljs-params">this</span>.<span class="hljs-params">getAttribute</span>('<span class="hljs-params">href</span>')</span>)<br><br> var offset = <span class="hljs-constructor">$(<span class="hljs-params">targetSelector</span>)</span>.offset<span class="hljs-literal">()</span>.top;<br><br> hasVelocity ?<br> html.velocity('stop').velocity('scroll', {<br> offset: offset + 'px',<br> mobileHA: <span class="hljs-literal">false</span><br> }) :<br> <span class="hljs-constructor">$('<span class="hljs-params">html</span>, <span class="hljs-params">body</span>')</span>.stop<span class="hljs-literal">()</span>.animate({<br> scrollTop: offset<br> }, <span class="hljs-number">500</span>);<br> });<br></code></pre></td></tr></table></figure>
<p> 经过上面的处理自动生成的目录可以正常跳转了,但是会根据页面的滑动区域自适应目录的展示,这对于需要根据目录直达指定内容的访客来说,很不方便,于是在css样式中对代码进行以下修改: 修改文件目录: <font color=camel>themes/next/source/css/_common/components/sidebar/sidebar-toc.styl</font></p>
<p> 找到如下的代码<br> <figure class="highlight stylus"><table><tr><td class="code"><pre><code class="hljs stylus"><span class="hljs-selector-class">.post-toc</span> <span class="hljs-selector-class">.nav</span> <span class="hljs-selector-class">.nav-child</span> { <span class="hljs-attribute">display</span>: none; }<br></code></pre></td></tr></table></figure><br> 修改为</p>
<figure class="highlight stylus"><table><tr><td class="code"><pre><code class="hljs stylus"><span class="hljs-selector-class">.post-toc</span> <span class="hljs-selector-class">.nav</span> <span class="hljs-selector-class">.nav-child</span> { <span class="hljs-attribute">display</span>: block; }<br><br></code></pre></td></tr></table></figure>
<h2 id="next主题添加代码块一键复制功能"><a href="#next主题添加代码块一键复制功能" class="headerlink" title="next主题添加代码块一键复制功能"></a>next主题添加代码块一键复制功能</h2><div class="note success modern"><p><a href="https://blog.csdn.net/Awt_FuDongLai/article/details/107466848">参考链接:hexo-next代码块复制粘贴—成功复现</a> </p>
</div>
]]></content>
<categories>
<category>hexo</category>
</categories>
<tags>
<tag>hexo</tag>
</tags>
</entry>
<entry>
<title>minio (一)</title>
<url>/2024/06/22/minio/4dbfabd1f48a/</url>
<content><![CDATA[<h1 id="minio"><a href="#minio" class="headerlink" title="minio"></a>minio</h1><p>minio的安装:</p>
<p><a href="https://www.minio.org.cn/download.shtml#/linux">以Linux系统安装为例</a></p>
<figure class="highlight awk"><table><tr><td class="code"><pre><code class="hljs awk">wget https:<span class="hljs-regexp">//</span>dl.minio.org.cn<span class="hljs-regexp">/server/mi</span>nio<span class="hljs-regexp">/release/</span>linux-amd64/minio<br>chmod +x minio<br>MINIO_ROOT_USER=admin MINIO_ROOT_PASSWORD=password .<span class="hljs-regexp">/minio server /m</span>nt/data --console-address <span class="hljs-string">":9001"</span><br></code></pre></td></tr></table></figure>
<div class="note warning modern"><p>其他:MINIO_ROOT_USER=mhist MINIO_ROOT_PASSWORD=mhist0129 ./minio server /mnt/data –console-address “:9001”</p>
<p> 运行以上命令的结果:<br> <img src="https://cdn.jsdelivr.net/gh/mhist/hexoImage@main/img/WechatIMG138.jpg"></p>
</div>
<ul>
<li>设置数据存放位置:/root/mhist/soft/minioFloder/data</li>
</ul>
<figure class="highlight awk"><table><tr><td class="code"><pre><code class="hljs awk">MINIO_ROOT_USER=mhist MINIO_ROOT_PASSWORD=mhist0129 .<span class="hljs-regexp">/minio server /</span>root<span class="hljs-regexp">/mhist/</span>soft<span class="hljs-regexp">/minioFloder/</span>data --console-address <span class="hljs-string">":9000"</span> --address <span class="hljs-string">":9001"</span><br><br></code></pre></td></tr></table></figure>
<ul>
<li>修改公网ip</li>
</ul>
<p>查看是否正常启动</p>
<figure class="highlight vim"><table><tr><td class="code"><pre><code class="hljs vim"><span class="hljs-keyword">ps</span> -ef|<span class="hljs-keyword">grep</span> minio<br></code></pre></td></tr></table></figure>
<p><img src="https://cdn.jsdelivr.net/gh/mhist/hexoImage@main/img/20240622170157.png"></p>
<figure class="highlight awk"><table><tr><td class="code"><pre><code class="hljs awk">腾讯云端口安全组放开<br>https:<span class="hljs-regexp">//</span>console.cloud.tencent.com<span class="hljs-regexp">/lighthouse/i</span>nstance/detail?rid=<span class="hljs-number">1</span>&id=lhins-qf8lj47h&tab=firewall<br></code></pre></td></tr></table></figure>
<p><img src="https://cdn.jsdelivr.net/gh/mhist/hexoImage@main/img/minioStartSuccess.png" alt="启动成功"></p>
<p>但是这种方式会在关闭终端的时候自动关闭、以至于无法访问、所以需要配置自动启动服务。</p>
<p>参考链接:<a href="https://juejin.cn/post/7172092483197730823">CentOS下安装Minio、搭建Minio集群、SpringBoot整合Minio</a></p>
<figure class="highlight ini"><table><tr><td class="code"><pre><code class="hljs ini"><span class="hljs-section">[Unit]</span><br><span class="hljs-attr">Description</span>=Minio Service<br><br><span class="hljs-section">[Service]</span><br><span class="hljs-attr">Environment</span>=<span class="hljs-string">"MINIO_ROOT_USER=mhist"</span><br><span class="hljs-attr">Environment</span>=<span class="hljs-string">"MINIO_ROOT_PASSWORD=mhistxxxx"</span><br><span class="hljs-attr">ExecStart</span>=/home/minio/minio server /home/minio/data --console-address <span class="hljs-string">":9001"</span> --address <span class="hljs-string">":9000"</span><br><span class="hljs-attr">ExecReload</span>=/bin/kill -s HUP <span class="hljs-variable">$MAINPID</span><br><span class="hljs-attr">ExecStop</span>=/bin/kill -s QUIT <span class="hljs-variable">$MAINPID</span><br><span class="hljs-attr">StandardOutput</span>=/home/minio/minio.log<br><span class="hljs-attr">PrivateTmp</span>=<span class="hljs-literal">true</span><br><br><span class="hljs-section">[Install]</span><br><span class="hljs-attr">WantedBy</span>=multi-user.target<br><br></code></pre></td></tr></table></figure>
<h3 id="开机自启"><a href="#开机自启" class="headerlink" title="开机自启"></a>开机自启</h3><figure class="highlight vala"><table><tr><td class="code"><pre><code class="hljs vala"><span class="hljs-meta"># 重新刷新</span><br>systemctl daemon-reload<br><span class="hljs-meta"># 启动</span><br>systemctl start minio.service<br><span class="hljs-meta"># 查看状态</span><br>systemctl status minio -l<br><span class="hljs-meta"># 开机自启</span><br>systemctl enable minio.service<br></code></pre></td></tr></table></figure>
<h3 id="其他命令"><a href="#其他命令" class="headerlink" title="其他命令"></a>其他命令</h3><figure class="highlight dsconfig"><table><tr><td class="code"><pre><code class="hljs dsconfig"><span class="hljs-comment"># 启动minio</span><br><span class="hljs-string">systemctl</span> <span class="hljs-string">start</span> <span class="hljs-string">minio</span><br> <br><span class="hljs-comment">#设置开机自启动</span><br><span class="hljs-string">systemctl</span> <span class="hljs-string">enable</span> <span class="hljs-string">minio</span> <br> <br><span class="hljs-comment">#停止开机自启动</span><br><span class="hljs-string">systemctl</span> <span class="hljs-string">disable</span> <span class="hljs-string">minio</span><br> <br><span class="hljs-comment">#查看服务当前状态 </span><br><span class="hljs-string">systemctl</span> <span class="hljs-string">status</span> <span class="hljs-string">minio</span><br> <br><span class="hljs-comment">#重新启动服务</span><br><span class="hljs-string">systemctl</span> <span class="hljs-string">restart</span> <span class="hljs-string">minio</span> <br> <br><span class="hljs-comment">#查看所有已启动的服务 </span><br><span class="hljs-string">systemctl</span> <span class="hljs-built_in">list-units</span> <span class="hljs-built_in">--type=service</span> <br><br></code></pre></td></tr></table></figure>
<h3 id="指定的后台API-(9000)-以及前端控制页面(9001)"><a href="#指定的后台API-(9000)-以及前端控制页面(9001)" class="headerlink" title="指定的后台API (9000) 以及前端控制页面(9001)"></a>指定的后台API (9000) 以及前端控制页面(9001)</h3><p><img src="https://cdn.jsdelivr.net/gh/mhist/hexoImage@main/img/20240622220709.png" alt="启动完成、得到指定的后台API (9000) 以及前端控制页面(9001)"></p>
<h1 id="图片用于markdown"><a href="#图片用于markdown" class="headerlink" title="图片用于markdown"></a>图片用于markdown</h1><p><img src="https://119.91.213.59:9001/api/v1/buckets/mhist/objects/download?preview=true&prefix=WX20240623-204304@2x.png&version_id=4153bbe5-aed9-4016-b17a-4bcc0c65b79e" alt="启动完成、得到指定的后台API (9000) 以及前端控制页面(9001)"></p>
<img src="https://119.91.213.59:9001/api/v1/buckets/mhist/objects/download?preview=true&prefix=WX20240623-204304@2x.png&version_id=4153bbe5-aed9-4016-b17a-4bcc0c65b79e"/>
<h1 id="升级minio服务为https"><a href="#升级minio服务为https" class="headerlink" title="升级minio服务为https"></a>升级minio服务为https</h1><h2 id="通过接口调用的时候报错"><a href="#通过接口调用的时候报错" class="headerlink" title="通过接口调用的时候报错"></a>通过接口调用的时候报错</h2><p><img src="https://cdn.jsdelivr.net/gh/mhist/hexoImage@main/img/errorHttps.png" alt="本地没有证书报错"></p>
<h2 id="使用keytool需要Java环境"><a href="#使用keytool需要Java环境" class="headerlink" title="使用keytool需要Java环境"></a>使用keytool需要Java环境</h2><p>对于zsh用户<br>macOS Catalina及以后,默认使用的是zsh。你需要编辑 ~/.zshrc 文件。同样,如果文件不存在则创建。使用以下命令编辑:</p>
<figure class="highlight arduino"><table><tr><td class="code"><pre><code class="hljs arduino">open -e ~/.zshrc<br></code></pre></td></tr></table></figure>
<p>在文件末尾添加与bash类似的行:</p>
<figure class="highlight routeros"><table><tr><td class="code"><pre><code class="hljs routeros"><span class="hljs-builtin-name">export</span> <span class="hljs-attribute">JAVA_HOME</span>=<span class="hljs-string">"/Users/jiangyadong/dev/jdk/jdk17/Contents/Home"</span><br><span class="hljs-builtin-name">export</span> <span class="hljs-attribute">PATH</span>=<span class="hljs-variable">$JAVA_HOME</span>/bin:$PATH<br></code></pre></td></tr></table></figure>
<p>保存并关闭文件后,运行以下命令使更改生效:</p>
<figure class="highlight bash"><table><tr><td class="code"><pre><code class="hljs bash"><span class="hljs-built_in">source</span> ~/.zshrc<br></code></pre></td></tr></table></figure>
<p>检验配置<br>最后,重启终端或新开一个终端窗口,运行 java -version 和 javac -version 来验证配置是否成功。如果一切设置正确,你应该能看到它们的版本信息。<br><img src="https://cdn.jsdelivr.net/gh/mhist/hexoImage@main/img/%E6%88%AA%E5%B1%8FJavaVersion.png" alt="javaVersion"></p>
<h2 id="安装证书"><a href="#安装证书" class="headerlink" title="安装证书"></a>安装证书</h2><p><img src="https://cdn.jsdelivr.net/gh/mhist/hexoImage@main/img/keyTool%E5%AE%89%E8%A3%85%E8%AF%81%E4%B9%A6.png" alt="通过keytool 安装证书 (保持与线上服务器自生成证书一致)"></p>
<h2 id="调用接口发现还是报错"><a href="#调用接口发现还是报错" class="headerlink" title="调用接口发现还是报错"></a>调用接口发现还是报错</h2><p><img src="https://cdn.jsdelivr.net/gh/mhist/hexoImage@main/img/20240624211315.png" alt="报错信息"></p>
<h2 id="重新生成证书"><a href="#重新生成证书" class="headerlink" title="重新生成证书"></a>重新生成证书</h2><p><img src="https://cdn.jsdelivr.net/gh/mhist/hexoImage@main/img/20240624211421.png" alt="重新生成证书"></p>
<p><img src="https://cdn.jsdelivr.net/gh/mhist/hexoImage@main/img/20240624211549.png" alt="alt text"></p>
<h2 id="重新生成、重新安装证书、重启idea"><a href="#重新生成、重新安装证书、重启idea" class="headerlink" title="重新生成、重新安装证书、重启idea"></a>重新生成、重新安装证书、重启idea</h2><h3 id="调用接口"><a href="#调用接口" class="headerlink" title="调用接口"></a>调用接口</h3><p><img src="https://cdn.jsdelivr.net/gh/mhist/hexoImage@main/img/20240624212019.png" alt="成功上传"></p>
<h3 id="验证结果"><a href="#验证结果" class="headerlink" title="验证结果"></a>验证结果</h3><p><img src="https://cdn.jsdelivr.net/gh/mhist/hexoImage@main/img/20240624212218.png" alt="验证上传结果"></p>
<h3 id="返回预览文件链接"><a href="#返回预览文件链接" class="headerlink" title="返回预览文件链接"></a>返回预览文件链接</h3><p><a href="https://119.91.213.59:9001/api/v1/buckets/mhist/objects/download?preview=true&prefix=certgen-linux-amd64&version_id=9e562776-7b5e-4480-af1f-199d956a59b3">文件链接</a></p>
<p><img src="https://cdn.jsdelivr.net/gh/mhist/hexoImage@main/img/20240624212450.png" alt="接口调用演示"></p>
<p>验证服务器图片是否能够访问:</p>
<p><img src="https://119.91.213.59:9001/api/v1/buckets/mhist/objects/download?preview=true&prefix=keyTool%E5%AE%89%E8%A3%85%E8%AF%81%E4%B9%A6.png&version_id=ab781a5d-a159-4487-a462-ac7c27aec162" alt="证书"></p>
]]></content>
<categories>
<category>minio</category>
</categories>
<tags>
<tag>minio</tag>
</tags>
</entry>
<entry>
<title>learn react</title>
<url>/2021/04/24/uncategorized/c98970b16c20/</url>
<content><![CDATA[<h1 id="react-入门"><a href="#react-入门" class="headerlink" title="react 入门"></a>react 入门</h1><h2 id="react框架基本介绍"><a href="#react框架基本介绍" class="headerlink" title="react框架基本介绍"></a>react框架基本介绍</h2><p> <a href="https://reactjs.org/">react官方</a></p>
<h2 id="开发环境及脚手架安装"><a href="#开发环境及脚手架安装" class="headerlink" title="开发环境及脚手架安装"></a>开发环境及脚手架安装</h2><ul>
<li>查看node版本<figure class="highlight crmsh"><table><tr><td class="code"><pre><code class="hljs crmsh"><span class="hljs-keyword">node</span> <span class="hljs-title">-v</span><br></code></pre></td></tr></table></figure>
v14.16.0</li>
<li>查看npm版本<figure class="highlight crmsh"><table><tr><td class="code"><pre><code class="hljs crmsh"><span class="hljs-keyword">node</span> <span class="hljs-title">-v</span><br></code></pre></td></tr></table></figure>
6.14.11</li>
<li>安装脚手架<figure class="highlight cmake"><table><tr><td class="code"><pre><code class="hljs cmake">npm <span class="hljs-keyword">install</span> -g create-react-app<br></code></pre></td></tr></table></figure>
cmd控制台反馈如下:<pre>
C:\Users\18827\AppData\Roaming\npm\create-react-app -> C:\Users\18827\AppData\Roaming\npm\node_modules\create-react-app\index.js</li>
</ul>
<p><a href="mailto:+create-react-app@4.0.3">+create-react-app@4.0.3</a><br>added 67 packages from 25 contributors in 22.805s<br> </pre></p>
<h2 id="创建项目文件夹,并开启demo"><a href="#创建项目文件夹,并开启demo" class="headerlink" title="创建项目文件夹,并开启demo"></a>创建项目文件夹,并开启demo</h2><ul>
<li><p>在电脑桌面同时按下Windows+R进入输入cmd,按enter</p>
</li>
<li><p>进入某个盘 例如 M:</p>
<figure class="highlight avrasm"><table><tr><td class="code"><pre><code class="hljs avrasm"><span class="hljs-symbol">m:</span><br></code></pre></td></tr></table></figure></li>
<li><p>创建文件夹</p>
<figure class="highlight arduino"><table><tr><td class="code"><pre><code class="hljs arduino">mkdir ReactDemo<br></code></pre></td></tr></table></figure></li>
<li><p>进入文件夹 </p>
<figure class="highlight bash"><table><tr><td class="code"><pre><code class="hljs bash"><span class="hljs-built_in">cd</span> ReactDemo<br></code></pre></td></tr></table></figure></li>
<li><p>创建demo01</p>
<figure class="highlight dsconfig"><table><tr><td class="code"><pre><code class="hljs dsconfig"><span class="hljs-built_in">create-react-app</span> <span class="hljs-string">demo01</span><br></code></pre></td></tr></table></figure></li>
<li><p>控制台反馈</p>
<span id="more"></span>
<figure class="highlight sql"><table><tr><td class="code"><pre><code class="hljs sql"> Microsoft Windows [版本 <span class="hljs-number">10.0</span><span class="hljs-number">.19042</span><span class="hljs-number">.928</span>]<br>(c) Microsoft Corporation。保留所有权利。<br><br>C:\Users\<span class="hljs-number">18827</span><span class="hljs-operator">></span>m:<br><br>M:\<span class="hljs-operator">></span>mkdir ReactDemo<br><br>M:\<span class="hljs-operator">></span>cd ReactDemo<br><br>M:\ReactDemo<span class="hljs-operator">></span><span class="hljs-keyword">create</span><span class="hljs-operator">-</span>react<span class="hljs-operator">-</span>app demo01<br><br>Creating a <span class="hljs-keyword">new</span> React app <span class="hljs-keyword">in</span> M:\ReactDemo\demo01.<br><br>Installing packages. This might take a couple <span class="hljs-keyword">of</span> minutes.<br>Installing react, react<span class="hljs-operator">-</span>dom, <span class="hljs-keyword">and</span> react<span class="hljs-operator">-</span>scripts <span class="hljs-keyword">with</span> cra<span class="hljs-operator">-</span>template...<br><br>yarn <span class="hljs-keyword">add</span> v1<span class="hljs-number">.22</span><span class="hljs-number">.10</span><br>[<span class="hljs-number">1</span><span class="hljs-operator">/</span><span class="hljs-number">4</span>] Resolving packages...<br>[<span class="hljs-number">2</span><span class="hljs-operator">/</span><span class="hljs-number">4</span>] Fetching packages...<br>info fsevents<span class="hljs-variable">@1</span><span class="hljs-number">.2</span><span class="hljs-number">.13</span>: The platform "win32" <span class="hljs-keyword">is</span> incompatible <span class="hljs-keyword">with</span> this module.<br>info "fsevents@1.2.13" <span class="hljs-keyword">is</span> an optional dependency <span class="hljs-keyword">and</span> failed compatibility check. Excluding it <span class="hljs-keyword">from</span> installation.<br>info fsevents<span class="hljs-variable">@2</span><span class="hljs-number">.3</span><span class="hljs-number">.2</span>: The platform "win32" <span class="hljs-keyword">is</span> incompatible <span class="hljs-keyword">with</span> this module.<br>info "fsevents@2.3.2" <span class="hljs-keyword">is</span> an optional dependency <span class="hljs-keyword">and</span> failed compatibility check. Excluding it <span class="hljs-keyword">from</span> installation.<br>[<span class="hljs-number">3</span><span class="hljs-operator">/</span><span class="hljs-number">4</span>] Linking dependencies...<br>warning "react-scripts > @typescript-eslint/eslint-plugin > tsutils@3.20.0" has unmet peer dependency "typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta".<br>[<span class="hljs-number">4</span><span class="hljs-operator">/</span><span class="hljs-number">4</span>] Building fresh packages...<br>success Saved lockfile.<br>success Saved <span class="hljs-number">7</span> <span class="hljs-keyword">new</span> dependencies.<br>info Direct dependencies<br>├─ cra<span class="hljs-operator">-</span>template<span class="hljs-variable">@1</span><span class="hljs-number">.1</span><span class="hljs-number">.2</span><br>├─ react<span class="hljs-operator">-</span>dom<span class="hljs-variable">@17</span><span class="hljs-number">.0</span><span class="hljs-number">.2</span><br>├─ react<span class="hljs-operator">-</span>scripts<span class="hljs-variable">@4</span><span class="hljs-number">.0</span><span class="hljs-number">.3</span><br>└─ react<span class="hljs-variable">@17</span><span class="hljs-number">.0</span><span class="hljs-number">.2</span><br>info <span class="hljs-keyword">All</span> dependencies<br>├─ cra<span class="hljs-operator">-</span>template<span class="hljs-variable">@1</span><span class="hljs-number">.1</span><span class="hljs-number">.2</span><br>├─ immer<span class="hljs-variable">@8</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span><br>├─ react<span class="hljs-operator">-</span>dev<span class="hljs-operator">-</span>utils<span class="hljs-variable">@11</span><span class="hljs-number">.0</span><span class="hljs-number">.4</span><br>├─ react<span class="hljs-operator">-</span>dom<span class="hljs-variable">@17</span><span class="hljs-number">.0</span><span class="hljs-number">.2</span><br>├─ react<span class="hljs-operator">-</span>scripts<span class="hljs-variable">@4</span><span class="hljs-number">.0</span><span class="hljs-number">.3</span><br>├─ react<span class="hljs-variable">@17</span><span class="hljs-number">.0</span><span class="hljs-number">.2</span><br>└─ scheduler<span class="hljs-variable">@0</span><span class="hljs-number">.20</span><span class="hljs-number">.2</span><br>Done <span class="hljs-keyword">in</span> <span class="hljs-number">241.60</span>s.<br><br>Initialized a git repository.<br><br>Installing template dependencies <span class="hljs-keyword">using</span> yarnpkg...<br>yarn <span class="hljs-keyword">add</span> v1<span class="hljs-number">.22</span><span class="hljs-number">.10</span><br>[<span class="hljs-number">1</span><span class="hljs-operator">/</span><span class="hljs-number">4</span>] Resolving packages...<br>[<span class="hljs-number">2</span><span class="hljs-operator">/</span><span class="hljs-number">4</span>] Fetching packages...<br>info fsevents<span class="hljs-variable">@2</span><span class="hljs-number">.3</span><span class="hljs-number">.2</span>: The platform "win32" <span class="hljs-keyword">is</span> incompatible <span class="hljs-keyword">with</span> this module.<br>info "fsevents@2.3.2" <span class="hljs-keyword">is</span> an optional dependency <span class="hljs-keyword">and</span> failed compatibility check. Excluding it <span class="hljs-keyword">from</span> installation.<br>info fsevents<span class="hljs-variable">@1</span><span class="hljs-number">.2</span><span class="hljs-number">.13</span>: The platform "win32" <span class="hljs-keyword">is</span> incompatible <span class="hljs-keyword">with</span> this module.<br>info "fsevents@1.2.13" <span class="hljs-keyword">is</span> an optional dependency <span class="hljs-keyword">and</span> failed compatibility check. Excluding it <span class="hljs-keyword">from</span> installation.<br>[<span class="hljs-number">3</span><span class="hljs-operator">/</span><span class="hljs-number">4</span>] Linking dependencies...<br>warning "react-scripts > @typescript-eslint/eslint-plugin > tsutils@3.20.0" has unmet peer dependency "typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta".<br>warning " > @testing-library/user-event@12.8.3" has unmet peer dependency "@testing-library/dom@>=7.21.4".<br>[<span class="hljs-number">4</span><span class="hljs-operator">/</span><span class="hljs-number">4</span>] Building fresh packages...<br>success Saved lockfile.<br>success Saved <span class="hljs-number">17</span> <span class="hljs-keyword">new</span> dependencies.<br>info Direct dependencies<br>├─ <span class="hljs-variable">@testing</span><span class="hljs-operator">-</span>library<span class="hljs-operator">/</span>jest<span class="hljs-operator">-</span>dom<span class="hljs-variable">@5</span><span class="hljs-number">.12</span><span class="hljs-number">.0</span><br>├─ <span class="hljs-variable">@testing</span><span class="hljs-operator">-</span>library<span class="hljs-operator">/</span>react<span class="hljs-variable">@11</span><span class="hljs-number">.2</span><span class="hljs-number">.6</span><br>├─ <span class="hljs-variable">@testing</span><span class="hljs-operator">-</span>library<span class="hljs-operator">/</span><span class="hljs-keyword">user</span><span class="hljs-operator">-</span>event<span class="hljs-variable">@12</span><span class="hljs-number">.8</span><span class="hljs-number">.3</span><br>├─ react<span class="hljs-operator">-</span>dom<span class="hljs-variable">@17</span><span class="hljs-number">.0</span><span class="hljs-number">.2</span><br>├─ react<span class="hljs-variable">@17</span><span class="hljs-number">.0</span><span class="hljs-number">.2</span><br>└─ web<span class="hljs-operator">-</span>vitals<span class="hljs-variable">@1</span><span class="hljs-number">.1</span><span class="hljs-number">.1</span><br>info <span class="hljs-keyword">All</span> dependencies<br>├─ <span class="hljs-variable">@testing</span><span class="hljs-operator">-</span>library<span class="hljs-operator">/</span>dom<span class="hljs-variable">@7</span><span class="hljs-number">.30</span><span class="hljs-number">.4</span><br>├─ <span class="hljs-variable">@testing</span><span class="hljs-operator">-</span>library<span class="hljs-operator">/</span>jest<span class="hljs-operator">-</span>dom<span class="hljs-variable">@5</span><span class="hljs-number">.12</span><span class="hljs-number">.0</span><br>├─ <span class="hljs-variable">@testing</span><span class="hljs-operator">-</span>library<span class="hljs-operator">/</span>react<span class="hljs-variable">@11</span><span class="hljs-number">.2</span><span class="hljs-number">.6</span><br>├─ <span class="hljs-variable">@testing</span><span class="hljs-operator">-</span>library<span class="hljs-operator">/</span><span class="hljs-keyword">user</span><span class="hljs-operator">-</span>event<span class="hljs-variable">@12</span><span class="hljs-number">.8</span><span class="hljs-number">.3</span><br>├─ <span class="hljs-variable">@types</span><span class="hljs-operator">/</span>aria<span class="hljs-operator">-</span>query<span class="hljs-variable">@4</span><span class="hljs-number">.2</span><span class="hljs-number">.1</span><br>├─ <span class="hljs-variable">@types</span><span class="hljs-operator">/</span>jest<span class="hljs-variable">@26</span><span class="hljs-number">.0</span><span class="hljs-number">.22</span><br>├─ <span class="hljs-variable">@types</span><span class="hljs-operator">/</span>testing<span class="hljs-operator">-</span>library__jest<span class="hljs-operator">-</span>dom<span class="hljs-variable">@5</span><span class="hljs-number">.9</span><span class="hljs-number">.5</span><br>├─ css.escape<span class="hljs-variable">@1</span><span class="hljs-number">.5</span><span class="hljs-number">.1</span><br>├─ css<span class="hljs-variable">@3</span><span class="hljs-number">.0</span><span class="hljs-number">.0</span><br>├─ dom<span class="hljs-operator">-</span>accessibility<span class="hljs-operator">-</span>api<span class="hljs-variable">@0</span><span class="hljs-number">.5</span><span class="hljs-number">.4</span><br>├─ lz<span class="hljs-operator">-</span>string<span class="hljs-variable">@1</span><span class="hljs-number">.4</span><span class="hljs-number">.4</span><br>├─ min<span class="hljs-operator">-</span>indent<span class="hljs-variable">@1</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span><br>├─ react<span class="hljs-operator">-</span>dom<span class="hljs-variable">@17</span><span class="hljs-number">.0</span><span class="hljs-number">.2</span><br>├─ react<span class="hljs-variable">@17</span><span class="hljs-number">.0</span><span class="hljs-number">.2</span><br>├─ redent<span class="hljs-variable">@3</span><span class="hljs-number">.0</span><span class="hljs-number">.0</span><br>├─ strip<span class="hljs-operator">-</span>indent<span class="hljs-variable">@3</span><span class="hljs-number">.0</span><span class="hljs-number">.0</span><br>└─ web<span class="hljs-operator">-</span>vitals<span class="hljs-variable">@1</span><span class="hljs-number">.1</span><span class="hljs-number">.1</span><br>Done <span class="hljs-keyword">in</span> <span class="hljs-number">22.61</span>s.<br>Removing template package <span class="hljs-keyword">using</span> yarnpkg...<br><br>yarn remove v1<span class="hljs-number">.22</span><span class="hljs-number">.10</span><br>[<span class="hljs-number">1</span><span class="hljs-operator">/</span><span class="hljs-number">2</span>] Removing <span class="hljs-keyword">module</span> cra<span class="hljs-operator">-</span>template...<br>[<span class="hljs-number">2</span><span class="hljs-operator">/</span><span class="hljs-number">2</span>] Regenerating lockfile <span class="hljs-keyword">and</span> installing missing dependencies...<br>info fsevents<span class="hljs-variable">@2</span><span class="hljs-number">.3</span><span class="hljs-number">.2</span>: The platform "win32" <span class="hljs-keyword">is</span> incompatible <span class="hljs-keyword">with</span> this module.<br>info "fsevents@2.3.2" <span class="hljs-keyword">is</span> an optional dependency <span class="hljs-keyword">and</span> failed compatibility check. Excluding it <span class="hljs-keyword">from</span> installation.<br>info fsevents<span class="hljs-variable">@1</span><span class="hljs-number">.2</span><span class="hljs-number">.13</span>: The platform "win32" <span class="hljs-keyword">is</span> incompatible <span class="hljs-keyword">with</span> this module.<br>info "fsevents@1.2.13" <span class="hljs-keyword">is</span> an optional dependency <span class="hljs-keyword">and</span> failed compatibility check. Excluding it <span class="hljs-keyword">from</span> installation.<br>warning " > @testing-library/user-event@12.8.3" has unmet peer dependency "@testing-library/dom@>=7.21.4".<br>warning "react-scripts > @typescript-eslint/eslint-plugin > tsutils@3.20.0" has unmet peer dependency "typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta".<br>success Uninstalled packages.<br>Done <span class="hljs-keyword">in</span> <span class="hljs-number">11.76</span>s.<br><br>Created git commit.<br><br>Success<span class="hljs-operator">!</span> Created demo01 <span class="hljs-keyword">at</span> M:\ReactDemo\demo01<br>Inside that directory, you can run several commands:<br><br> yarn <span class="hljs-keyword">start</span><br> Starts the development server.<br><br> yarn build<br> Bundles the app <span class="hljs-keyword">into</span> <span class="hljs-keyword">static</span> files <span class="hljs-keyword">for</span> production.<br><br> yarn test<br> Starts the test runner.<br><br> yarn eject<br> Removes this tool <span class="hljs-keyword">and</span> copies build dependencies, configuration files<br> <span class="hljs-keyword">and</span> scripts <span class="hljs-keyword">into</span> the app directory. If you do this, you can’t go back<span class="hljs-operator">!</span><br><br>We suggest that you <span class="hljs-keyword">begin</span> <span class="hljs-keyword">by</span> typing:<br><br> cd demo01<br> yarn <span class="hljs-keyword">start</span><br><br>Happy hacking<span class="hljs-operator">!</span><br></code></pre></td></tr></table></figure>
<h3 id="记录一下yarn相关指令"><a href="#记录一下yarn相关指令" class="headerlink" title="记录一下yarn相关指令"></a>记录一下yarn相关指令</h3><p>Inside that directory, you can run several commands:</p>
<figure class="highlight crmsh"><table><tr><td class="code"><pre><code class="hljs crmsh">yarn <span class="hljs-literal">start</span><br></code></pre></td></tr></table></figure>
<p>Starts the development server.</p>
<figure class="highlight ebnf"><table><tr><td class="code"><pre><code class="hljs ebnf"><span class="hljs-attribute">yarn build</span><br></code></pre></td></tr></table></figure>
<p>Bundles the app into static files for production.</p>
<figure class="highlight bash"><table><tr><td class="code"><pre><code class="hljs bash">yarn <span class="hljs-built_in">test</span><br></code></pre></td></tr></table></figure>
<p>Starts the test runner.</p>
<figure class="highlight ebnf"><table><tr><td class="code"><pre><code class="hljs ebnf"><span class="hljs-attribute">yarn eject</span><br></code></pre></td></tr></table></figure>
<p>Removes this tool and copies build dependencies, configuration files and scripts into the app directory. If you do this, you can’t go back!</p>
<h2 id="按照提示指令启动项目"><a href="#按照提示指令启动项目" class="headerlink" title="按照提示指令启动项目"></a>按照提示指令启动项目</h2><figure class="highlight dos"><table><tr><td class="code"><pre><code class="hljs dos"><span class="hljs-built_in">cd</span> demo01<br> yarn <span class="hljs-built_in">start</span><br></code></pre></td></tr></table></figure></li>
<li><p>控制台反馈<br>Compiled successfully!</p>
</li>
</ul>
<p>You can now view demo01 in the browser.</p>
<p> Local: <a href="http://localhost:3000/">http://localhost:3000</a><br> On Your Network: <a href="http://192.168.5.23:3000/">http://192.168.5.23:3000</a></p>
<p>Note that the development build is not optimized.<br>To create a production build, use yarn build.</p>
<ul>
<li>点击上述任一链接即可看到、即说明项目demo搭建成功!<br><img src="https://gitee.com/mhist/hexo-image/raw/master/img/ReactDemo-20210424120256.gif" alt="ReactDemo"></li>
</ul>
]]></content>
<tags>
<tag>react</tag>
</tags>
</entry>
<entry>
<title>mysql-多表</title>
<url>/2021/11/14/mysql/6220192bee46/</url>
<content><![CDATA[<h1 id="聚合函数"><a href="#聚合函数" class="headerlink" title="聚合函数"></a>聚合函数</h1><pre>
# 1.聚合函数的使用 所有数据当作一组
# 求所有手机的价格的总和
SELECT SUM(price) FROM `product`;
# 求所有华为手机的价格的总和
SELECT SUM(price) FROM `product` WHERE brand = '华为';
# 求所有华为手机的平均价格
SELECT AVG(price) FROM `product` WHERE brand = '华为';
# 求手机的最高价格
SELECT MAX(price) FROM `product`;
SELECT MIN(price) FROM `product`;
# 1.求华为手机的个数
SELECT COUNT(*) FROM `product` WHERE brand = '华为';
SELECT COUNT(*) FROM `product` WHERE brand = '苹果';
SELECT COUNT(url) FROM `product` WHERE brand = '苹果';
SELECT COUNT(price) FROM `product`;
SELECT COUNT(DISTINCT price) FROM `product`; #多个相同的价格只计算入一个
# 2. GROUP BY 分组: 华为、苹果、小米、vivo各自一组
SELECT brand , AVG(price),COUNT(*),AVG(score) FROM `product` GROUP BY brand;
# 3. 在上条的基础上加上:平均价格>2000d的手机 HAVING的使用
SELECT brand , AVG(price) avgprice ,COUNT(*),AVG(score) FROM `product` GROUP BY brand HAVING avgprice > 2000 ;
# 分组后查结果用having,它作用于GGROUP BY,分组前查询结果用WHERE,WHERE作用于表
# 4.评分大于7.5的手机的平均价格
SELECT AVG(price) FROM `product` WHERE score > 7.5;
# 5.求所有手机 评分7.5以上,然后按照品牌分类,求出各自的平均价格
SELECT brand,AVG(price) FROM `product` WHERE score > 7.5 GROUP BY brand;
</pre>
<h2 id="多表查询"><a href="#多表查询" class="headerlink" title="多表查询"></a>多表查询</h2><p>我们如果是希望在查询到产品时,显示对应的品牌的相关信息,因为数据是存放在两张表中,所以这个时候就需要进行多表查询。</p>
<p>如果我们直接通过查询语句希望在多张表中查询到数据,这个时候是什么效果呢?</p>
<p>例如:现在又两张表</p>
<figure class="highlight n1ql"><table><tr><td class="code"><pre><code class="hljs n1ql"><span class="hljs-keyword">SELECT</span> * <span class="hljs-keyword">FROM</span> <span class="hljs-symbol">`product`</span>, <span class="hljs-symbol">`brand`</span>;<br></code></pre></td></tr></table></figure>
<p><img src="https://cdn.jsdelivr.net/gh/mhist/hexoImage@main/img/20211114171128moreTableQuery.png" alt="多表查询"></p>
<p>可见,在这样子进行多表查询时,其数据量是两表数量的乘积,笛卡尔乘积。</p>
<figure class="highlight n1ql"><table><tr><td class="code"><pre><code class="hljs n1ql"><span class="hljs-keyword">SELECT</span> * <span class="hljs-keyword">FROM</span> <span class="hljs-symbol">`product`</span>, <span class="hljs-symbol">`brand`</span> <span class="hljs-keyword">WHERE</span> product.brand_id = brand.id;<br></code></pre></td></tr></table></figure>
<p>真实开发中,常用连接 join的方式,进行多表之间的连接 sql-join</p>
<ol>
<li>左连接</li>
<li>右连接</li>
<li>内连接</li>
<li>全连接</li>
</ol>
<p>具体语句可参考 <a href="https://www.runoob.com/sql/sql-join.html">菜鸟教程</a></p>
]]></content>
<categories>
<category>mysql</category>
</categories>
<tags>
<tag>mysql</tag>
</tags>
</entry>
<entry>
<title>mysql-语句</title>
<url>/2021/11/12/mysql/de9d27f5d5d1/</url>
<content><![CDATA[<h1 id="终端操作缺陷"><a href="#终端操作缺陷" class="headerlink" title="终端操作缺陷"></a>终端操作缺陷</h1><p><a href="http://wakeweb.cloud/2021/11/12/mysql/ab03683a0789/">参考终端进行数据库操作文章</a></p>
<ol>
<li>语句无高亮,并且无任何提示</li>
<li>复杂的语句分成多行,格式不美观,且输入容易出错</li>
<li>终端查看所有的数据库和数据时不方便</li>
</ol>
<h1 id="GUI工具"><a href="#GUI工具" class="headerlink" title="GUI工具"></a>GUI工具</h1><p>为了解决上述问题,可以采用以下几款:</p>
<ol>
<li>Navicat: 推荐使用,不过需要付费,但是又免费的试用时间,应付学习足够了。</li>
<li>SQLYog: 一款免费的SQL工具</li>
<li>TablePlus:常用功能都可以使用,但是会有一些限制(例如:只能开两个标签页)</li>
</ol>
<h1 id="mysql-语句"><a href="#mysql-语句" class="headerlink" title="mysql 语句"></a>mysql 语句</h1><p>sql(structured Query Language) —结构化查询语言</p>
<h2 id="sql语句的常用规范"><a href="#sql语句的常用规范" class="headerlink" title="sql语句的常用规范"></a>sql语句的常用规范</h2><ol>
<li><p>通常关键字是大写的,比如CREATE,TABLE,SHOW等等。</p>
</li>
<li><p>一条语句结束后,需要以“;”结尾。</p>
</li>
<li><p>如果遇到关键字作为表明或者字段名称,可以用 <code> </code> 包裹。(类似es6中的模板字符串)</p>
</li>
</ol>
<h2 id="sql语句分类"><a href="#sql语句分类" class="headerlink" title="sql语句分类"></a>sql语句分类</h2><ol>
<li>DDL (Data Definition language) —数据定义语言</li>
</ol>
<ul>
<li>可以通过DDL语句对数据库或者表进行: 创建,删除,修改操作.</li>
</ul>
<ol start="2">
<li>DML(Data Manipulation Language): 数据操作语言</li>
</ol>
<ul>
<li>可以通过DML语句对表进行: 添加、删除、修改等操作.</li>
</ul>
<ol start="3">
<li>DQL(Data Query Language): 数据查询语言</li>
</ol>
<ul>
<li>可以通过DQL语句对表进行查询操作.</li>
</ul>
<ol start="4">
<li>DCL(Data Control Language): 数据权限语言</li>
</ol>
<ul>
<li>可以通过DCL语句对表权限等操作.</li>
</ul>
<h3 id="DDL数据库的操作—实践"><a href="#DDL数据库的操作—实践" class="headerlink" title="DDL数据库的操作—实践"></a>DDL数据库的操作—实践</h3><pre># 查看所有的数据
SHOW DATABASES;
# 选择某一个数据
USE bili;
#查看当前正在使用的数据库
SELECT DATABASE();
# 创建一个新的数据库
-- CREATE DATABASE douyu;
-- CREATE DATABASE IF NOT EXISTS douyu;
CREATE DATABASE IF NOT EXISTS huya DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;
# 删除数据库
DROP DATABASE IF EXISTS douyu;
# 修改数据库的编码
ALTER DATABASE huya CHARACTER SET = utf8 COLLATE = utf8_unicode_ci;
</pre>
<h3 id="DDL-数据表的操作—实践"><a href="#DDL-数据表的操作—实践" class="headerlink" title="DDL-数据表的操作—实践"></a>DDL-数据表的操作—实践</h3><pre># 查看数据表
SHOW TABLES;
# 查看某一个表结构
DESC users;
# 创建数据表
CREATE TABLE IF NOT EXISTS `test` (
`name` VARCHAR(20),
age INT,
height DOUBLE
);
# 删除表
DROP TABLE IF EXISTS `test`;
# 查看某一个表结构
DESC students;
</pre>
<h3 id="DML-对数据库进行增删改—实践"><a href="#DML-对数据库进行增删改—实践" class="headerlink" title="DML-对数据库进行增删改—实践"></a>DML-对数据库进行增删改—实践</h3><pre>
# 插入数据
INSERT INTO `user` VALUES (110, 'why', '020-123456', '2020-10-20', '2020-11-11');
-- INSERT INTO `user` (`name`, `telPhone`,`createTime`,`updateTime`)
-- VALUES ('paike','000-1111112','2020-10-10','2030-10-20');
# 需求: createTime和updateTime可以自动设置值
ALTER TABLE `user` MODIFY `createTime` TIMESTAMP DEFAULT CURRENT_TIMESTAMP;
ALTER TABLE `user` MODIFY `updateTime` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
ON UPDATE CURRENT_TIMESTAMP;
INSERT INTO `user` (`name`, `telPhone`)
VALUES ('lilei3','000-1111116');
# 删除数据
# 删除所有数据
DELETE FROM `user`;
# 删除符合条件的数据
DELETE FROM `user` WHERE id = 110;
# 更新数据
# 更新所有数据
UPDATE `user` SET `name` = 'lily',telPhone = '010-110110';
# 更新符合条件的数据
UPDATE `user` SET `name` = 'lily',telPhone = '010-110110' WHERE id = 115;
</pre>
<h3 id="DQL-对数据库进行查询—实践"><a href="#DQL-对数据库进行查询—实践" class="headerlink" title="DQL-对数据库进行查询—实践"></a>DQL-对数据库进行查询—实践</h3><pre>
</pre>
<h4 id="分页查询"><a href="#分页查询" class="headerlink" title="分页查询"></a>分页查询</h4><p>当数据库中的数据非常多时,一次性查询到所有的将结果进行显示是不现实的;</p>
<ol>
<li><p>在真实开发中,我们都会要求用户传入offset、limit、或者page等字段</p>
</li>
<li><p>它们的目的是让我们可以在数据库中进行分页查询</p>
</li>
<li><p>它的用法有[LIMIT{[offset, row_count | row_count OFFSET offset]}]</p>