-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vue1-0.html
1322 lines (731 loc) · 46 KB
/
Vue1-0.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head hexo-theme='https://volantis.js.org/#2.1.2'>
<meta charset="utf-8">
<!-- SEO相关 -->
<!-- 渲染优化 -->
<meta name="renderer" content="webkit">
<meta name="force-rendering" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
<meta name="HandheldFriendly" content="True" >
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<!-- 页面元数据 -->
<title>Vue初识 - CRainyDay</title>
<meta name="keywords" content="JS,Vue">
<meta name="description" content="初步认识VUE">
<!-- feed -->
<!-- import meta -->
<!-- link -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/[email protected]/css/all.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/[email protected]/dist/jquery.fancybox.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/waves.min.css">
<link rel="shortcut icon" type='image/x-icon' href="https://cdn.jsdelivr.net/gh/crainyday/blog@master/favicon.ico">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/APlayer.min.css">
<!-- import link -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/crainyday/blog@master/css/style.css">
<script>
function setLoadingBarProgress(num) {
document.getElementById('loading-bar').style.width=num+"%";
}
</script>
<!-- ba -->
<script>
var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?bf368df5385d5be3472f3155e4cdb303";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
</script>
</head>
<body>
<div id="loading-bar-wrapper">
<div id="loading-bar"></div>
</div>
<header class="l_header shadow floatable blur">
<div class='wrapper'>
<div class='nav-sub container--flex'>
<a class="logo flat-box"></a>
<ul class='switcher h-list'>
<li><a class="s-comment flat-btn fas fa-comments fa-fw" target="_self" href='javascript:void(0)'></a></li>
<li><a class="s-toc flat-btn fas fa-list fa-fw" target="_self" href='javascript:void(0)'></a></li>
</ul>
</div>
<div class="nav-main container container--flex">
<a class="logo flat-box" target="_self" href='/'>
<i class='fas fa-home'></i>
CRainyDay
</a>
<div class='menu navigation'>
<ul class='h-list'>
<li>
<a class="flat-box" href=/categories/
id="categories"
>
<i class='fas fa-folder-open fa-fw'></i>
分类
</a>
</li>
<li>
<a class="flat-box" href=/archives/
id="archives"
>
<i class='fas fa-archive fa-fw'></i>
归档
</a>
</li>
<li>
<a class="flat-box" href=/tags/
id="tags"
>
<i class='fas fa-tags fa-fw'></i>
标签
</a>
</li>
<li>
<a class="flat-box" href=/friends/
id="friends"
>
<i class='fas fa-link fa-fw'></i>
友链
</a>
</li>
<li>
<a class="flat-box"
>
<i class='fas fa-ellipsis-v fa-fw'></i>
更多
</a>
<ul class="submenu">
<li>
<a class="flat-box" href=/about/music.html
id="aboutmusic.html"
>
<i class='fas fa-music fa-fw'></i>
往后余生
</a>
</li>
<hr>
<li>
<a class="flat-box" href=/bbs/
id="bbs"
>
<i class='fas fa-comment-alt fa-fw'></i>
留言
</a>
</li>
<hr>
<li>
<a class="flat-box" href=/about/
id="about"
>
<i class='fas fa-info-circle fa-fw'></i>
关于
</a>
</li>
</ul>
</li>
</ul>
</div>
<div class="m_search">
<form name="searchform" class="form u-search-form">
<i class="icon fas fa-search fa-fw"></i>
<input type="text" class="input u-search-input" placeholder="搜索" />
</form>
</div>
<ul class='switcher h-list'>
<li><a class="s-search flat-btn fas fa-search fa-fw" target="_self" href='javascript:void(0)'></a></li>
<li><a class="s-menu flat-btn fas fa-bars fa-fw" target="_self" href='javascript:void(0)'></a></li>
</ul>
</div>
</div>
</header>
<ul class="menu-phone navigation white-box">
<li>
<a class="flat-box" href=/
id="home"
>
<i class='fas fa-home fa-fw'></i>
博客
</a>
</li>
<li>
<a class="flat-box" href=/archives/
id="archives"
>
<i class='fas fa-archive fa-fw'></i>
归档
</a>
</li>
<li>
<a class="flat-box" href=/categories/
id="categories"
>
<i class='fas fa-folder-open fa-fw'></i>
分类
</a>
</li>
<li>
<a class="flat-box" href=/friends/
id="friends"
>
<i class='fas fa-link fa-fw'></i>
友链
</a>
</li>
<li>
<a class="flat-box" href=/bbs/
id="bbs"
>
<i class='fas fa-comment-alt fa-fw'></i>
留言
</a>
</li>
<li>
<a class="flat-box" href=/about/
id="about"
>
<i class='fas fa-info-circle fa-fw'></i>
关于
</a>
</li>
</ul>
<script>setLoadingBarProgress(40);</script>
<div class="l_body nocover">
<div class='body-wrapper'>
<div class='l_main'>
<article id="post" class="post white-box shadow floatable article-type-post" itemscope itemprop="blogPost">
<section class='meta'>
<a title='Vue初识' href='/Vue1-0.html'><img class='thumbnail' src='https://cdn.jsdelivr.net/gh/crainyday/blog@master/imgs/more/more05.png'></a>
<div class="meta" id="header-meta">
<h1 class="title">
<a href="/Vue1-0.html">
Vue初识
</a>
</h1>
<div class='new-meta-box'>
<div class='new-meta-item author'>
<a href="https://crainyday.gitee.io" rel="nofollow">
<img src="https://cdn.jsdelivr.net/gh/crainyday/blog@master/lazyload.svg" data-original="https://cdn.jsdelivr.net/gh/crainyday/blog@master/avatar.png">
<p>crainyday</p>
</a>
</div>
<div class='new-meta-item category'>
<a href='/categories/%E5%89%8D%E7%AB%AF/Vue/' rel="nofollow">
<i class="fas fa-folder-open" aria-hidden="true"></i>
<p>前端 / Vue</p>
</a>
</div>
<div class="new-meta-item date">
<a class='notlink'>
<i class="fas fa-edit" aria-hidden="true"></i>
<p>发布于:2019年7月28日</p>
</a>
</div>
<div class="new-meta-item wordcount">
<a class='notlink'>
<i class="fas fa-keyboard" aria-hidden="true"></i>
<p>字数:1.2k字</p>
</a>
</div>
<div class="new-meta-item readtime">
<a class='notlink'>
<i class="fas fa-hourglass-half" aria-hidden="true"></i>
<p>时长:5分钟</p>
</a>
</div>
</div>
<hr>
</div>
</section>
<section class="article typo">
<div class="article-entry" itemprop="articleBody">
<p>初步认识VUE</p>
<a id="more"></a>
<h2 id="1-Vue-js是什么">1. Vue.js是什么?</h2>
<ul>
<li>
<ol>
<li>一位华裔前Google工程师(尤雨溪)开发的<strong>前端js库</strong></li>
</ol>
</li>
<li>
<ol start="2">
<li>作用: 动态构建用户界面即前端界面</li>
</ol>
</li>
<li>
<ol start="3">
<li>特点:</li>
</ol>
<p>①遵循MVVM模式, M指Model数据, V指View, VM指的是view Model对象</p>
<p>②编码简洁, 体积小, 运行效率高, 移动/PC端开发</p>
<p>③它本身只关注UI, 可以轻松引入vue插件和其它第三库开发项目</p>
</li>
<li>
<ol start="4">
<li>与其它框架的关联:</li>
</ol>
<p>①借鉴angular的<strong>模板</strong>和<strong>数据绑定</strong>技术</p>
<p>②借鉴react的<strong>组件化</strong>和<strong>虚拟DOM</strong>技术</p>
</li>
<li>
<ol start="5">
<li>Vue包含一系列的扩展插件(库):</li>
</ol>
<p>①vue-cli: vue脚手架</p>
<p>②vue-resource(axios): ajax请求</p>
<p>③vue-router: 路由</p>
<p>④vuex: 状态管理</p>
<p>⑤vue-lazyload: 图片懒加载</p>
<p>⑥vue-scroller: 页面滑动相关</p>
<p>⑦mint-ui: 基于vue的组件库(移动端)</p>
<p>⑧element-ui: 基于vue的组件库(PC端)</p>
</li>
</ul>
<h2 id="2-基本使用">2. 基本使用</h2>
<ol>
<li>
<p>引入vue.js文件</p>
</li>
<li>
<p>创建Vue实例对象(vm), 指定选项(配置)对象</p>
<p>el : 指定Dom标签容器的选择器<br>
data : 指定初始化状态数据的对象/函数(返回一个对象)</p>
</li>
<li>
<p>在页面模板中使用}}或vue指令, 来显示数据</p>
</li>
</ol>
<p>例子:</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">body</span>></span></span><br><span class="line"><span class="comment"><!--</span></span><br><span class="line"><span class="comment"> 1. 引入Vue.js</span></span><br><span class="line"><span class="comment"> 2. 创建Vue对象</span></span><br><span class="line"><span class="comment"> el : 指定根element(选择器)</span></span><br><span class="line"><span class="comment"> data : 初始化数据(页面可以访问)</span></span><br><span class="line"><span class="comment"> 3. 双向数据绑定 : v-model</span></span><br><span class="line"><span class="comment"> 4. 显示数据 : {{xxx}}</span></span><br><span class="line"><span class="comment"> 5. 理解vue的mvvm实现</span></span><br><span class="line"><span class="comment">--></span></span><br><span class="line"> <span class="comment"><!--实现输入框与p标签的显示数据同步更新--></span></span><br><span class="line"> <span class="tag"><<span class="name">div</span> <span class="attr">id</span>=<span class="string">"app"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">input</span> <span class="attr">type</span>=<span class="string">"text"</span> <span class="attr">v-model</span>=<span class="string">"username"</span> /></span></span><br><span class="line"> <span class="tag"><<span class="name">p</span>></span>Hello {{username}}<span class="tag"></<span class="name">p</span>></span></span><br><span class="line"> <span class="tag"></<span class="name">div</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">script</span> <span class="attr">src</span>=<span class="string">"https://cdn.jsdelivr.net/npm/vue"</span>></span><span class="undefined"></span><span class="tag"></<span class="name">script</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">script</span> <span class="attr">type</span>=<span class="string">"text/javascript"</span>></span><span class="undefined"></span></span><br><span class="line"><span class="actionscript"> <span class="comment">//创建vm实例</span></span></span><br><span class="line"><span class="actionscript"> <span class="keyword">const</span> vm = <span class="keyword">new</span> Vue({<span class="comment">//配置对象</span></span></span><br><span class="line"><span class="actionscript"> el:<span class="string">'#app'</span>,</span></span><br><span class="line"><span class="undefined"> data:{</span></span><br><span class="line"><span class="actionscript"> username:<span class="string">'Vue!'</span></span></span><br><span class="line"><span class="undefined"> }</span></span><br><span class="line"><span class="undefined"> })</span></span><br><span class="line"><span class="undefined"> </span><span class="tag"></<span class="name">script</span>></span></span><br><span class="line"><span class="comment"><!--</span></span><br><span class="line"><span class="comment">MVVM:</span></span><br><span class="line"><span class="comment">model:模型,即数据对象(data)</span></span><br><span class="line"><span class="comment">view:视图,模板页面</span></span><br><span class="line"><span class="comment">viewModel:视图模型,即Vue的一个实例</span></span><br><span class="line"><span class="comment">--></span></span><br><span class="line"><span class="tag"></<span class="name">body</span>></span></span><br></pre></td></tr></table></figure>
<h2 id="3-模板的常见语法">3.模板的常见语法</h2>
<blockquote>
<p>模板(视图)的理解:<br>
动态的html页面, 包含了一些JS语法代码、大括号表达式、指令(以v-开头的自定义标签属性).</p>
</blockquote>
<blockquote>
<p>(1)双大括号表达式<br>
语法: {{exp}} 或 {{{exp}}}<br>
功能: 向页面输出数据, 可以调用对象的方法</p>
</blockquote>
<blockquote>
<p>(2)VUE指令:</p>
<p>①强制数据绑定<br>
功能: 指定变化的属性值<br>
完整写法: v-bind:xxx=‘yyy’ //yyy会作为表达式解析执行<br>
简洁写法: :xxx=‘yyy’</p>
<p>②绑定事件监听<br>
功能: 绑定指定事件名的回调函数<br>
完整写法: v-on:click=‘xxx’<br>
简洁写法: @click=‘xxx’</p>
</blockquote>
<p>例子:</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">div</span> <span class="attr">id</span>=<span class="string">"demo"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">h2</span>></span>1. 双大括号表达式<span class="tag"></<span class="name">h2</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">p</span>></span>{{content}}<span class="tag"></<span class="name">p</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">p</span>></span>{{content.toUpperCase()}}<span class="tag"></<span class="name">p</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">p</span> <span class="attr">v-text</span>=<span class="string">"tag"</span>></span><span class="tag"></<span class="name">p</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">p</span> <span class="attr">v-html</span>=<span class="string">"tag"</span>></span><span class="tag"></<span class="name">p</span>></span></span><br><span class="line"> </span><br><span class="line"> <span class="tag"><<span class="name">h2</span>></span>2. 指令一: 强制数据绑定<span class="tag"></<span class="name">h2</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">a</span> <span class="attr">href</span>=<span class="string">"url"</span>></span>访问指定站点<span class="tag"></<span class="name">a</span>></span><span class="tag"><<span class="name">br</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">a</span> <span class="attr">v-bind:href</span>=<span class="string">"url"</span>></span>访问指定站点2<span class="tag"></<span class="name">a</span>></span><span class="tag"><<span class="name">br</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">a</span> <span class="attr">:href</span>=<span class="string">"url"</span>></span>访问指定站点3<span class="tag"></<span class="name">a</span>></span><span class="tag"><<span class="name">br</span>></span></span><br><span class="line"></span><br><span class="line"> <span class="tag"><<span class="name">h2</span>></span>3. 指令二: 绑定事件监听<span class="tag"></<span class="name">h2</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">button</span> <span class="attr">v-on:click</span>=<span class="string">"test1"</span>></span>点我<span class="tag"></<span class="name">button</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">button</span> @<span class="attr">click</span>=<span class="string">"test2(content)"</span>></span>点我<span class="tag"></<span class="name">button</span>></span><span class="comment"><!--带参的方法--></span></span><br><span class="line"><span class="tag"></<span class="name">div</span>></span></span><br><span class="line"><span class="tag"><<span class="name">script</span> <span class="attr">src</span>=<span class="string">"https://cdn.jsdelivr.net/npm/vue"</span>></span><span class="undefined"></span><span class="tag"></<span class="name">script</span>></span></span><br><span class="line"><span class="tag"><<span class="name">script</span> <span class="attr">type</span>=<span class="string">"text/javascript"</span>></span><span class="undefined"></span></span><br><span class="line"><span class="actionscript"> <span class="keyword">new</span> Vue({</span></span><br><span class="line"><span class="actionscript"> el:<span class="string">"#demo"</span>,</span></span><br><span class="line"><span class="undefined"> data:{</span></span><br><span class="line"><span class="actionscript"> content:<span class="string">"Hello Vue!!!"</span>,</span></span><br><span class="line"><span class="handlebars"><span class="xml"> tag:"<span class="tag"><<span class="name">a</span> <span class="attr">href</span>=<span class="string">'https://www.baidu.com/'</span>></span>test<span class="tag"></<span class="name">a</span>></span>",</span></span></span><br><span class="line"><span class="actionscript"> url:<span class="string">"https://www.baidu.com/"</span></span></span><br><span class="line"><span class="undefined"> },</span></span><br><span class="line"><span class="undefined"> methods:{</span></span><br><span class="line"><span class="actionscript"> test1(event){<span class="comment">//默认事件参数</span></span></span><br><span class="line"><span class="undefined"> alert(event);</span></span><br><span class="line"><span class="actionscript"> alert(<span class="string">"test1()"</span>);</span></span><br><span class="line"><span class="undefined"> },</span></span><br><span class="line"><span class="undefined"> test2(value){</span></span><br><span class="line"><span class="actionscript"> alert(<span class="string">"test2("</span>+value+<span class="string">")"</span>);</span></span><br><span class="line"><span class="undefined"> }</span></span><br><span class="line"><span class="undefined"> }</span></span><br><span class="line"><span class="undefined"> });</span></span><br><span class="line"><span class="undefined"></span><span class="tag"></<span class="name">script</span>></span></span><br></pre></td></tr></table></figure>
<h2 id="4-Vue对象的常用配置选项">4. Vue对象的常用配置选项</h2>
<ul>
<li>
<blockquote>
<p>①el:</p>
<p>指定dom标签容器的选择器, Vue就会管理对应的标签及其子标签</p>
</blockquote>
</li>
<li>
<blockquote>
<p>②data: 对象或函数类型<br>
指定初始化状态属性数据的对象, vm也会自动拥有data中所有属性, 页面中可以直接访问使用<br>
数据代理: 由vm对象来代理对data中所有属性的操作(读/写)</p>
</blockquote>
</li>
<li>
<blockquote>
<p>③methods: 包含多个方法的对象<br>
供页面中的事件指令来绑定回调, 回调函数默认有event参数, 但也可以指定自己的参数<br>
所有的方法由vue对象来调用, 访问data中的属性直接使用 <a href="http://this.xxx" target="_blank" rel="noopener">this.xxx</a></p>
</blockquote>
</li>
<li>
<blockquote>
<p>④computed: 包含多个方法的对象<br>
对状态属性进行计算返回一个新的数据, 供页面获取显示<br>
一般情况下是相当于是一个只读的属性<br>
利用set/get方法来实现属性数据的计算读取, 同时监视属性数据的变化<br>
如何给对象定义get/set属性<br>
在创建对象时指定: get name () {return xxx} / set name (value) {}<br>
对象创建之后指定: Object.defineProperty(obj, age, {get(){}, set(value){}})</p>
</blockquote>
</li>
<li>
<blockquote>
<p>⑤watch: 包含多个属性监视的对象<br>
分为一般监视和深度监视<br>
xxx: function(value){}<br>
xxx : {<br>
deep : true,<br>
handler : fun(value)<br>
}<br>
另一种添加监视方式: vm.$watch(‘xxx’, function(value){})</p>
</blockquote>
</li>
</ul>
<br>
<section class="widget copyright desktop mobile">
<div class='content'>
<blockquote>
<p>博客内容遵循 署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0) 协议</p>
<p>本文永久链接是:<a href=https://crainyday.gitee.io/Vue1-0.html>https://crainyday.gitee.io/Vue1-0.html</a></p>
</blockquote>
</div>
</section>
<section class="widget qrcode desktop mobile">
<div class='content article-entry'>
<fancybox><img src='https://cdn.jsdelivr.net/gh/crainyday/blog@master/alipay.png'
height='64px'
></fancybox>
<fancybox><img src='https://cdn.jsdelivr.net/gh/crainyday/blog@master/wechat.png'
height='64px'
></fancybox>
</div>
</section>
</div>
<section class='meta' id="footer-meta">
<div class='new-meta-box'>
<div class="new-meta-item date" itemprop="dateUpdated" datetime="2020-03-12T15:03:00+08:00">
<a class='notlink'>
<i class="fas fa-save" aria-hidden="true"></i>
<p>更新于:2020年3月12日</p>
</a>
</div>
<div class="new-meta-item meta-tags"><a class="tag" href="/tags/JS/" rel="nofollow"><i class="fas fa-hashtag" aria-hidden="true"></i><p>JS</p></a></div> <div class="new-meta-item meta-tags"><a class="tag" href="/tags/Vue/" rel="nofollow"><i class="fas fa-hashtag" aria-hidden="true"></i><p>Vue</p></a></div>
<div class="new-meta-item wordcount">
<a class='notlink'>
<i class="fas fa-keyboard" aria-hidden="true"></i>
<p>字数:1.2k字</p>
</a>
</div>
<div class="new-meta-item readtime">
<a class='notlink'>
<i class="fas fa-hourglass-half" aria-hidden="true"></i>
<p>时长:5分钟</p>
</a>
</div>
<div class="new-meta-item share -mob-share-list">
<div class="-mob-share-list share-body">
<a class="-mob-share-qq" title="" rel="external nofollow noopener noreferrer"
href="http://connect.qq.com/widget/shareqq/index.html?url=https://crainyday.gitee.io/Vue1-0.html&title=Vue初识 - CRainyDay&pics=https://cdn.jsdelivr.net/gh/crainyday/blog@master/imgs/more/more05.png&summary=初步认识VUE"
>
<img src="https://cdn.jsdelivr.net/gh/crainyday/blog@master/lazyload.svg" data-original="https://cdn.jsdelivr.net/gh/xaoxuu/cdn-assets/logo/128/qq.png">
</a>
<a class="-mob-share-qzone" title="" rel="external nofollow noopener noreferrer"
href="https://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=https://crainyday.gitee.io/Vue1-0.html&title=Vue初识 - CRainyDay&pics=https://cdn.jsdelivr.net/gh/crainyday/blog@master/imgs/more/more05.png&summary=初步认识VUE"
>
<img src="https://cdn.jsdelivr.net/gh/crainyday/blog@master/lazyload.svg" data-original="https://cdn.jsdelivr.net/gh/xaoxuu/cdn-assets/logo/128/qzone.png">
</a>
<a class="-mob-share-weibo" title="" rel="external nofollow noopener noreferrer"
href="http://service.weibo.com/share/share.php?url=https://crainyday.gitee.io/Vue1-0.html&title=Vue初识 - CRainyDay&pics=https://cdn.jsdelivr.net/gh/crainyday/blog@master/imgs/more/more05.png&summary=初步认识VUE"
>
<img src="https://cdn.jsdelivr.net/gh/crainyday/blog@master/lazyload.svg" data-original="https://cdn.jsdelivr.net/gh/xaoxuu/cdn-assets/logo/128/weibo.png">
</a>
<div class='hoverbox'>
<a><img src="https://cdn.jsdelivr.net/gh/crainyday/blog@master/lazyload.svg" data-original="https://cdn.jsdelivr.net/gh/xaoxuu/cdn-assets/logo/128/wechat.png"></a>
<div class='target'>
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPgAAAD4CAAAAADkunTXAAACT0lEQVR42u3aSXICMQwF0L7/pZMDpChragLq5x1UD3pmI/R9/Tx0XeDg4ODg4IvgV3G9uv/03D+FJO9r1wsODg4ODr4QHm4AXhRyui763NN97XrBwcHBwcEXw6MNxKnwaKNTfU75enBwcHBwcPD05+rgYGpwAQ4ODg4ODh5vYKKNSXaQAQ4ODg4ODj4XKFQbjekNeXuSAg4ODg4O/kHw8oG5f/pcrhccHBwcHHwRvLvuGjDctcDBwcHBwTfBuwOD6SCgG2gcHeDg4ODg4AvhpwZiakCQbYCqz00HCuDg4ODg4F8Ir25AFVI9cDBWHzg4ODg4+APh1cKr30cDhtsbGHBwcHBw8C+CZwcN3YFG9P3ZAwrhExHg4ODg4OAL4NkCqkF+N8DIDiKODQw4ODg4OPgXw9tBe3Ng0D1QAA4ODg4ODn61N2IquL9rsAEODg4ODr4ZftdBvOhgIrsB2feAg4ODg4NvhFcH+d0BwtTAIfsDgoODg4ODb4J3oVMbFA0mqsEFODg4ODj4Rnj1AED2QEB1Y6aCBHBwcHBw8M3wbmFTA4tuAwQODg4ODv5EePePfzagHxssZDcWHBwcHBx8EbzbIGQHBtWGpRqAHJMUcHBwcHDwBfBqQ1EdSESDgWwDc6wfHBwcHBx8MbzasFS/PxU+3lCBg4ODg4ODjx3grwKjDcwxUAAHBwcHBwcPDwK6Bw2yDRM4ODg4OPiT4NlAITs4yDYe2R/gbQcDwMHBwcHBPwieXekXRoP7qeAAHBwcHBz8AfCnLXBwcHBw8AXrF7M+xF+U6uJLAAAAAElFTkSuQmCC">
</div>
</div>
</div>
</div>
</div>
</section>
<div class="prev-next">
<a class='prev' href='/Vue1-1.html'>
<p class='title'><i class="fas fa-chevron-left" aria-hidden="true"></i>Vue的计算属性与监视</p>
<p class='content'>计算属性—>computed 监视—>watch
1.计算属性
在computed属性对象中定义计算属性的方法, 在页面中使用{{方法名}}来显示计算的结果.
在使用计算属性时...</p>
</a>
<a class='next' href='/JDBC1-10.html'>
<p class='title'>JDBC-DBUtils<i class="fas fa-chevron-right" aria-hidden="true"></i></p>
<p class='content'>DBUtils------Apache下的一个JDBC开源工具类库
1.Apache—DBUtils简介
commons-dbutils 是 Apache 组织提供的一个开源 JDBC工...</p>
</a>
</div>
</section>
</article>
<section class="widget related_posts shadow floatable desktop mobile">
<header>
<i class="fas fa-bookmark fa-fw" aria-hidden="true"></i><span class='name'>相关文章</span>
</header>
<div class="content">
<ul class="popular-posts"><li class="popular-posts-item"><div class="popular-posts-title"><h3><a href="/Vue3-1.html" title="JS数组函数" rel="bookmark">JS数组函数</a></h3></div></li><li class="popular-posts-item"><div class="popular-posts-title"><h3><a href="/Vue1-1.html" title="Vue的计算属性与监视" rel="bookmark">Vue的计算属性与监视</a></h3></div></li><li class="popular-posts-item"><div class="popular-posts-title"><h3><a href="/JS_tools_01.html" title="JS中UTF-8与汉字互转" rel="bookmark">JS中UTF-8与汉字互转</a></h3></div></li><li class="popular-posts-item"><div class="popular-posts-title"><h3><a href="/jQuery1-6.html" title="jQuery中的动画" rel="bookmark">jQuery中的动画</a></h3></div></li><li class="popular-posts-item"><div class="popular-posts-title"><h3><a href="/Vue5-1.html" title="vuex初识" rel="bookmark">vuex初识</a></h3></div></li></ul>
</div>
</section>
<!-- 显示推荐文章和评论 -->
<article class="post white-box comments shadow floatable">
<section class="article typo">
<p ct><i class='fas fa-comments'></i> 评论</p>
<section id="comments">
<div id="valine_container" class="valine_thread">
<i class="fas fa-spinner fa-spin fa-fw"></i>
</div>
</section>
</section>
</article>
<!-- 根据页面mathjax变量决定是否加载MathJax数学公式js -->
<script>
window.subData = {
title: 'Vue初识',
tools: true
}
</script>
</div>
<aside class='l_side'>
<section class="widget related_posts shadow floatable desktop mobile">
<header>
<i class="fas fa-bookmark fa-fw" aria-hidden="true"></i><span class='name'>相关文章</span>
</header>
<div class="content">
<ul class="popular-posts"><li class="popular-posts-item"><div class="popular-posts-title"><h3><a href="/Vue3-1.html" title="JS数组函数" rel="bookmark">JS数组函数</a></h3></div></li><li class="popular-posts-item"><div class="popular-posts-title"><h3><a href="/Vue1-1.html" title="Vue的计算属性与监视" rel="bookmark">Vue的计算属性与监视</a></h3></div></li><li class="popular-posts-item"><div class="popular-posts-title"><h3><a href="/JS_tools_01.html" title="JS中UTF-8与汉字互转" rel="bookmark">JS中UTF-8与汉字互转</a></h3></div></li><li class="popular-posts-item"><div class="popular-posts-title"><h3><a href="/jQuery1-6.html" title="jQuery中的动画" rel="bookmark">jQuery中的动画</a></h3></div></li><li class="popular-posts-item"><div class="popular-posts-title"><h3><a href="/Vue5-1.html" title="vuex初识" rel="bookmark">vuex初识</a></h3></div></li></ul>
</div>
</section>
<section class="widget grid shadow floatable desktop mobile">
<header>
<i class="fas fa-map-signs fa-fw" aria-hidden="true"></i><span class='name'>实用文档</span>
</header>
<div class='content'>
<div class="grid navigation fixed">
<a class="flat-box" title="/maven_05.html" href="/maven_05.html"
id="maven_05.html">
<i class="fas fa-file fa-fw" aria-hidden="true"></i>
Maven工程
</a>
<a class="flat-box" title="/Flask.html" href="/Flask.html"
id="Flask.html">
<i class="fas fa-file fa-fw" aria-hidden="true"></i>
Flask应用
</a>
<a class="flat-box" title="/Hexo.html" href="/Hexo.html"
id="Hexo.html">
<i class="fas fa-file fa-fw" aria-hidden="true"></i>
Gitee搭站
</a>
<a class="flat-box" title="/Ubuntu_006.html" href="/Ubuntu_006.html"
id="Ubuntu_006.html">
<i class="fas fa-file fa-fw" aria-hidden="true"></i>
v2ray
</a>
</div>
</div>
</section>
<section class="widget toc-wrapper shadow floatable desktop mobile">
<header>
<i class="fas fa-list fa-fw" aria-hidden="true"></i><span class='name'>本文目录</span>
</header>
<div class='content'>