Skip to content

Commit 5e3acc1

Browse files
vuejs-jp-botkazupon
authored andcommittedJan 6, 2018
Added "Why vue" en, cn srt files into assets folder (vuejs#1367) (vuejs#592)
* added english srt file * added chinese srt file * typo
1 parent 09836ad commit 5e3acc1

File tree

2 files changed

+1135
-0
lines changed

2 files changed

+1135
-0
lines changed
 

‎assets/why-vue/chinese.js.srt

+547
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,547 @@
1+
1
2+
00:00:00,000 --> 00:00:02,418
3+
- 在过去的 10 年时间里
4+
我们的网页变得
5+
6+
2
7+
00:00:02,418 --> 00:00:05,600
8+
更加动态化和强大了
9+
多亏有 JavaScript
10+
11+
3
12+
00:00:05,600 --> 00:00:07,541
13+
我们已经把很多传统的
14+
15+
4
16+
00:00:07,541 --> 00:00:10,120
17+
服务端代码放到了浏览器中
18+
19+
5
20+
00:00:10,120 --> 00:00:13,051
21+
这样就产生了成千上万行的 JavaScript 代码
22+
23+
6
24+
00:00:13,051 --> 00:00:15,691
25+
它们连接了各式各样的 HTML 和 CSS 文件
26+
27+
7
28+
00:00:15,691 --> 00:00:17,821
29+
但缺乏正规的组织形式
30+
31+
8
32+
00:00:17,821 --> 00:00:19,781
33+
这也是为什么越来越多的开发者使用
34+
35+
9
36+
00:00:19,781 --> 00:00:23,948
37+
诸如 Angular、React 或 Vue 这样的
38+
JavaScript 框架
39+
40+
10
41+
00:00:24,821 --> 00:00:27,829
42+
Vue 是一款值得拥有的、多用途且高性能的
43+
44+
11
45+
00:00:27,829 --> 00:00:29,860
46+
JavaScript 框架
47+
它能够帮助你创建
48+
49+
12
50+
00:00:29,860 --> 00:00:33,381
51+
可维护性和可测试性更强的代码库
52+
53+
13
54+
00:00:33,381 --> 00:00:36,229
55+
Vue 是渐进式的 JavaScript 框架
56+
也就是说
57+
58+
14
59+
00:00:36,229 --> 00:00:38,621
60+
如果你已经有一个现成的服务端应用
61+
62+
15
63+
00:00:38,621 --> 00:00:41,627
64+
你可以将 Vue 作为该应用的一部分嵌入其中
65+
66+
16
67+
00:00:41,627 --> 00:00:44,381
68+
带来更加丰富的交互体验
69+
70+
17
71+
00:00:44,381 --> 00:00:46,269
72+
或者,如果你希望将更多业务逻辑
73+
74+
18
75+
00:00:46,269 --> 00:00:48,240
76+
放到前端来实现
77+
78+
19
79+
00:00:48,240 --> 00:00:50,611
80+
Vue 的核心库及其生态系统
81+
82+
20
83+
00:00:50,611 --> 00:00:52,421
84+
绝对可以满足你的各式需求
85+
86+
21
87+
00:00:52,421 --> 00:00:53,829
88+
和其它前端框架一样
89+
90+
22
91+
00:00:53,829 --> 00:00:55,960
92+
Vue 允许你将一个网页分割成
93+
94+
23
95+
00:00:55,960 --> 00:01:00,000
96+
可复用的组件
97+
每个组件都包含属于自己的 HTML
98+
99+
24
100+
00:01:00,000 --> 00:01:02,291
101+
CSS、JavaScript 以用来渲染
102+
103+
25
104+
00:01:02,291 --> 00:01:04,269
105+
网页中相应的地方
106+
107+
26
108+
00:01:04,269 --> 00:01:06,260
109+
接下来我们就亲自动手感受一下 Vue
110+
111+
27
112+
00:01:06,260 --> 00:01:08,301
113+
我们来构建一个商品库存的页面
114+
115+
28
116+
00:01:08,301 --> 00:01:10,187
117+
也尽请关注视频结尾
118+
119+
29
120+
00:01:10,187 --> 00:01:13,571
121+
来自 Vue 的作者尤雨溪发来的信息
122+
123+
30
124+
00:01:13,571 --> 00:01:15,301
125+
我们不是教你如何使用 Vue
126+
127+
31
128+
00:01:15,301 --> 00:01:16,981
129+
而是介绍一些核心概念
130+
131+
32
132+
00:01:16,981 --> 00:01:19,460
133+
正是这些东西让 Vue 如此实用
134+
135+
33
136+
00:01:19,460 --> 00:01:21,200
137+
和许多 JavaScript 应用一样
138+
139+
34
140+
00:01:21,200 --> 00:01:24,272
141+
我们从网页中需要展示的数据开始
142+
143+
35
144+
00:01:24,272 --> 00:01:26,591
145+
使用 Vue 的起步非常简单
146+
147+
36
148+
00:01:26,591 --> 00:01:29,745
149+
我们引入 Vue 库
150+
创建一个 Vue 的实例
151+
152+
37
153+
00:01:29,745 --> 00:01:33,673
154+
然后通过应用的 id 嵌入到我们的根元素中
155+
156+
38
157+
00:01:33,673 --> 00:01:36,032
158+
el 是元素 (element) 的缩写
159+
160+
39
161+
00:01:36,032 --> 00:01:39,505
162+
我们还要将数据放入一个对象
163+
164+
40
165+
00:01:39,505 --> 00:01:41,993
166+
并且将 X 修改为一个表达式
167+
168+
41
169+
00:01:41,993 --> 00:01:44,544
170+
用双大括号括起来
171+
172+
42
173+
00:01:44,544 --> 00:01:46,945
174+
如你所看到的,它已经工作起来了
175+
176+
43
177+
00:01:46,945 --> 00:01:50,695
178+
非常好,但是 Vue 的魔力在数据变更时才会出现
179+
180+
44
181+
00:01:50,695 --> 00:01:51,975
182+
如果我们打开控制台
183+
184+
45
185+
00:01:51,975 --> 00:01:54,735
186+
改变 product 的值
187+
188+
46
189+
00:01:54,735 --> 00:01:57,324
190+
注意在 product 的值改变的同时
191+
192+
47
193+
00:01:57,324 --> 00:01:59,953
194+
Vue 自动更新了我们的 HTML
195+
196+
48
197+
00:01:59,953 --> 00:02:01,745
198+
这是因为 Vue 是响应式的
199+
200+
49
201+
00:02:01,745 --> 00:02:03,273
202+
也就是说当我们的数据变更时
203+
204+
50
205+
00:02:03,273 --> 00:02:05,193
206+
Vue 会帮你更新所有
207+
208+
51
209+
00:02:05,193 --> 00:02:07,255
210+
网页中用到它的地方
211+
212+
52
213+
00:02:07,255 --> 00:02:10,305
214+
除了字符串,Vue 对其它类型的数据也是如此
215+
216+
53
217+
00:02:10,305 --> 00:02:11,604
218+
所以我们把这个简单的商品换成
219+
220+
54
221+
00:02:11,604 --> 00:02:14,604
222+
一个商品数组试试看
223+
224+
55
225+
00:02:14,604 --> 00:02:17,865
226+
然后我们将 <h2>
227+
改为一个无序列表
228+
229+
56
230+
00:02:17,865 --> 00:02:20,535
231+
再为数组中的每个商品
232+
创建一个列表项
233+
234+
57
235+
00:02:20,535 --> 00:02:22,618
236+
使用 Vue 的 v-for 指令
237+
238+
58
239+
00:02:24,353 --> 00:02:26,615
240+
让每个商品都拥有各自的列表项
241+
242+
59
243+
00:02:26,615 --> 00:02:28,495
244+
如你这里看到的
245+
246+
60
247+
00:02:28,495 --> 00:02:30,352
248+
这也是一个小小的亮点
249+
250+
61
251+
00:02:30,352 --> 00:02:32,312
252+
现在我们先从空列表开始
253+
254+
62
255+
00:02:32,312 --> 00:02:34,815
256+
然后从一个实际的 API 获取我们的商品信息
257+
258+
63
259+
00:02:34,815 --> 00:02:37,433
260+
这个 API 是从某个数据库获取来的
261+
262+
64
263+
00:02:37,433 --> 00:02:38,863
264+
当应用被创建时
265+
266+
65
267+
00:02:38,863 --> 00:02:41,866
268+
我们会从这个 API 获取最新的商品信息
269+
270+
66
271+
00:02:41,866 --> 00:02:43,199
272+
这就是你要从这里获取的全部
273+
274+
67
275+
00:02:43,199 --> 00:02:45,063
276+
我们获取商品列表
277+
278+
68
279+
00:02:45,063 --> 00:02:46,923
280+
并把它们更新到我们的数据中
281+
282+
69
283+
00:02:46,923 --> 00:02:48,281
284+
如你所看到的,在我们的网页中
285+
286+
70
287+
00:02:48,281 --> 00:02:51,435
288+
各列表项展示了该 API 返回的对象
289+
290+
71
291+
00:02:51,435 --> 00:02:53,474
292+
好吧,这还不是常人能读懂的样子
293+
294+
72
295+
00:02:53,474 --> 00:02:56,265
296+
所以我们来改变一下它的展示方式
297+
298+
73
299+
00:02:56,265 --> 00:02:59,643
300+
我们将打印出其数量和名称
301+
302+
74
303+
00:02:59,643 --> 00:03:02,265
304+
就这样就可以了,打印出来的效果非常好
305+
306+
75
307+
00:03:02,265 --> 00:03:03,563
308+
我们可能需要特别留意
309+
310+
76
311+
00:03:03,563 --> 00:03:05,675
312+
数量为零的项目
313+
314+
77
315+
00:03:05,675 --> 00:03:09,595
316+
所以我们添加一个 <span>
317+
写入文字 OUT OF STOCK
318+
319+
78
320+
00:03:09,595 --> 00:03:13,334
321+
这个区域会在项目数量为零的时候出现
322+
323+
79
324+
00:03:13,334 --> 00:03:16,134
325+
这里我们用到了 v-if 指令
326+
327+
80
328+
00:03:16,134 --> 00:03:20,362
329+
因为我们的 jacket 数量为零,它卖完了
330+
331+
81
332+
00:03:20,362 --> 00:03:22,081
333+
如果我们想要打印出
334+
335+
82
336+
00:03:22,081 --> 00:03:24,641
337+
列表中商品的总数该怎么办呢?
338+
339+
83
340+
00:03:24,641 --> 00:03:26,468
341+
为了做这件事,我们需要创建
342+
343+
84
344+
00:03:26,468 --> 00:03:29,570
345+
一个名为 totalProducts 的计算属性
346+
347+
85
348+
00:03:29,570 --> 00:03:34,228
349+
它会返回我们所有商品的数量总和
350+
351+
86
352+
00:03:34,228 --> 00:03:36,490
353+
也许你对 JavaScript 的 reduce 不熟悉
354+
355+
87
356+
00:03:36,490 --> 00:03:40,468
357+
它在这里用来把每个商品的数量加在一起
358+
359+
88
360+
00:03:40,468 --> 00:03:41,851
361+
如你所看到的,在我们的浏览器中
362+
363+
89
364+
00:03:41,851 --> 00:03:45,308
365+
它已经把总数量准确的加起来了
366+
367+
90
368+
00:03:45,308 --> 00:03:47,588
369+
现在我将要在浏览器中向你展示
370+
371+
91
372+
00:03:47,588 --> 00:03:51,380
373+
Vue 的 Chrome 插件
374+
我们可以在这里看到我们的数组数据
375+
376+
92
377+
00:03:51,380 --> 00:03:53,547
378+
并就地对其进行审查
379+
380+
93
381+
00:03:55,108 --> 00:03:57,460
382+
现在我们在命令行中,为了好玩
383+
384+
94
385+
00:03:57,460 --> 00:03:59,850
386+
我们来把数组中最后一个项目 pop 出来
387+
388+
95
389+
00:03:59,850 --> 00:04:01,828
390+
看看会发生什么
391+
392+
96
393+
00:04:01,828 --> 00:04:04,359
394+
如你所看到的,不仅我们的列表同步更新了
395+
396+
97
397+
00:04:04,359 --> 00:04:07,940
398+
连我们的商品总数也在预料之内的同步更新了
399+
400+
98
401+
00:04:07,940 --> 00:04:10,410
402+
接下来,让我们在页面中添加一些交互行为
403+
404+
99
405+
00:04:10,410 --> 00:04:12,346
406+
通过按钮来完成
407+
408+
100
409+
00:04:12,346 --> 00:04:14,490
410+
我们将为每一个商品创建一个增加按钮
411+
412+
101
413+
00:04:14,490 --> 00:04:15,850
414+
当点击它时
415+
416+
102
417+
00:04:15,850 --> 00:04:18,850
418+
就将商品数量加一
419+
420+
103
421+
00:04:19,959 --> 00:04:22,279
422+
回到浏览器,注意当我们添加一个项目时会怎样
423+
424+
104
425+
00:04:22,279 --> 00:04:25,159
426+
不只是更新整个库存
427+
428+
105
429+
00:04:25,159 --> 00:04:27,780
430+
同时当我们增加 jacket 商品数量时
431+
432+
106
433+
00:04:27,780 --> 00:04:30,300
434+
我们的 OUT OF STOCK 提示不见了
435+
436+
107
437+
00:04:30,300 --> 00:04:31,860
438+
如果你想点击这个按钮很多次
439+
440+
108
441+
00:04:31,860 --> 00:04:33,890
442+
那一定很烦,所以如果我们想要
443+
444+
109
445+
00:04:33,890 --> 00:04:37,719
446+
直接写入 jacket 或 hiking sock 的数量
447+
该怎么办呢?
448+
449+
110
450+
00:04:37,719 --> 00:04:40,580
451+
我们只需创建一个文本框
452+
453+
111
454+
00:04:40,580 --> 00:04:43,867
455+
并通过 v-model 指令
456+
绑定我们的商品数量字段
457+
458+
112
459+
00:04:43,867 --> 00:04:46,519
460+
指明这一定是个数字
461+
462+
113
463+
00:04:46,519 --> 00:04:48,060
464+
你会发现,现在我可以输入
465+
466+
114
467+
00:04:48,060 --> 00:04:52,450
468+
每个项目的总数
469+
并且数据会被立刻更新
470+
471+
115
472+
00:04:52,450 --> 00:04:54,500
473+
我甚至可以将数量设置回零
474+
475+
116
476+
00:04:54,500 --> 00:04:57,899
477+
这样我就又看到 OUT OF STOCK 的声明了
478+
479+
117
480+
00:04:57,899 --> 00:05:01,232
481+
而我的增加按钮仍然可以正常工作
482+
483+
118
484+
00:05:02,259 --> 00:05:03,999
485+
如果我们构建一个大型的应用
486+
487+
119
488+
00:05:03,999 --> 00:05:05,839
489+
在这一点上
490+
我们可能需要将东西分割
491+
492+
120
493+
00:05:05,839 --> 00:05:09,290
494+
成为各自的组件和文件
495+
496+
121
497+
00:05:09,290 --> 00:05:11,827
498+
Vue 甚至有一个命令行工具
499+
500+
122
501+
00:05:11,827 --> 00:05:15,828
502+
使快速开启一个真实的工程变得非常简单
503+
504+
123
505+
00:05:15,828 --> 00:05:18,879
506+
我们甚至可以使用 Vue 的单文件组件
507+
508+
124
509+
00:05:18,879 --> 00:05:21,770
510+
它包含了各自的 HTML、JavaScrept
511+
512+
125
513+
00:05:21,770 --> 00:05:23,687
514+
以及带作用域的 CSS 或 SCSS
515+
516+
126
517+
00:05:25,599 --> 00:05:28,926
518+
- Hi,我是尤雨溪,Vue.js 的作者
519+
520+
127
521+
00:05:28,926 --> 00:05:31,587
522+
你现在看到的仅仅是
523+
524+
128
525+
00:05:31,587 --> 00:05:33,065
526+
Vue 可以做的一些皮毛的小事情
527+
528+
129
529+
00:05:33,065 --> 00:05:34,856
530+
在我们的生态系统之中有各种丰富的东西
531+
532+
130
533+
00:05:34,856 --> 00:05:36,555
534+
可以帮助你构建、组织
535+
536+
131
537+
00:05:36,555 --> 00:05:39,076
538+
发展你的前端应用
539+
540+
132
541+
00:05:39,076 --> 00:05:42,457
542+
如果想更深入的了解 Vue
543+
请立刻阅读我们的文档
544+
545+
133
546+
00:05:42,457 --> 00:05:44,708
547+
我想你会乐在其中的

‎assets/why-vue/english.js.srt

+588
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,588 @@
1+
1
2+
00:00:00,000 --> 00:00:02,418
3+
- Over the last 10 years
4+
our web pages have become
5+
6+
2
7+
00:00:02,418 --> 00:00:05,600
8+
more dynamic and powerful
9+
thanks to JavaScript.
10+
11+
3
12+
00:00:05,600 --> 00:00:07,541
13+
We've moved a lot of
14+
code that was normally on
15+
16+
4
17+
00:00:07,541 --> 00:00:10,120
18+
the server side into our browsers,
19+
20+
5
21+
00:00:10,120 --> 00:00:13,051
22+
leaving us with thousands
23+
of lines of JavaScript code
24+
25+
6
26+
00:00:13,051 --> 00:00:15,691
27+
connecting to various HTML and CSS files
28+
29+
7
30+
00:00:15,691 --> 00:00:17,821
31+
with no formal organization.
32+
33+
8
34+
00:00:17,821 --> 00:00:19,781
35+
This is why more and
36+
more developers are using
37+
38+
9
39+
00:00:19,781 --> 00:00:23,948
40+
JavaScript frameworks like,
41+
Angular, React, or Vue.
42+
43+
10
44+
00:00:24,821 --> 00:00:27,829
45+
Vue is an approachable,
46+
versatile, and performant
47+
48+
11
49+
00:00:27,829 --> 00:00:29,860
50+
JavaScript framework
51+
that helps you create
52+
53+
12
54+
00:00:29,860 --> 00:00:33,381
55+
a more maintainable,
56+
and testable code base.
57+
58+
13
59+
00:00:33,381 --> 00:00:36,229
60+
Vue is a progressive JavaScript
61+
framework, which means,
62+
63+
14
64+
00:00:36,229 --> 00:00:38,621
65+
if you have an existing
66+
server-side application,
67+
68+
15
69+
00:00:38,621 --> 00:00:41,627
70+
you can plug Vue into just
71+
one part of your application
72+
73+
16
74+
00:00:41,627 --> 00:00:44,381
75+
that needs a richer, more
76+
interactive experience.
77+
78+
17
79+
00:00:44,381 --> 00:00:46,269
80+
Or, if you want to build
81+
more business logic
82+
83+
18
84+
00:00:46,269 --> 00:00:48,240
85+
into your frontend from the get go,
86+
87+
19
88+
00:00:48,240 --> 00:00:50,611
89+
Vue has the core libraries
90+
and the ecosystem
91+
92+
20
93+
00:00:50,611 --> 00:00:52,421
94+
you'll need to scale.
95+
96+
21
97+
00:00:52,421 --> 00:00:53,829
98+
Like other frontend frameworks,
99+
100+
22
101+
00:00:53,829 --> 00:00:55,960
102+
Vue allows you to take a
103+
web page and split it up
104+
105+
23
106+
00:00:55,960 --> 00:01:00,000
107+
into reusable components,
108+
each having its own HTML,
109+
110+
24
111+
00:01:00,000 --> 00:01:02,291
112+
CSS, and JavaScript needed to render
113+
114+
25
115+
00:01:02,291 --> 00:01:04,269
116+
that piece of the page.
117+
118+
26
119+
00:01:04,269 --> 00:01:06,260
120+
Next, we'll take a look
121+
at Vue in action by
122+
123+
27
124+
00:01:06,260 --> 00:01:08,301
125+
building a product inventory page,
126+
127+
28
128+
00:01:08,301 --> 00:01:10,187
129+
but stay tuned to the end of the video
130+
131+
29
132+
00:01:10,187 --> 00:01:13,571
133+
for a message from
134+
Vue's creator, Evan You.
135+
136+
30
137+
00:01:13,571 --> 00:01:15,301
138+
We won't be teaching you how to use Vue,
139+
140+
31
141+
00:01:15,301 --> 00:01:16,981
142+
but we'll introduce a couple key concepts
143+
144+
32
145+
00:01:16,981 --> 00:01:19,460
146+
that make Vue so useful.
147+
148+
33
149+
00:01:19,460 --> 00:01:21,200
150+
As with many JavaScript applications,
151+
152+
34
153+
00:01:21,200 --> 00:01:24,272
154+
we start from the need to
155+
display data on to our web page.
156+
157+
35
158+
00:01:24,272 --> 00:01:26,591
159+
With Vue, it starts out really simple.
160+
161+
36
162+
00:01:26,591 --> 00:01:29,745
163+
We include the Vue library,
164+
create a Vue instance,
165+
166+
37
167+
00:01:29,745 --> 00:01:33,673
168+
and plug into our root
169+
element with the ID of app.
170+
171+
38
172+
00:01:33,673 --> 00:01:36,032
173+
E L stands for element.
174+
175+
39
176+
00:01:36,032 --> 00:01:39,505
177+
We'll also move our data inside an object
178+
179+
40
180+
00:01:39,505 --> 00:01:41,993
181+
and change X into an expression
182+
183+
41
184+
00:01:41,993 --> 00:01:44,544
185+
with the double curly braces.
186+
187+
42
188+
00:01:44,544 --> 00:01:46,945
189+
As you can see, it works.
190+
191+
43
192+
00:01:46,945 --> 00:01:50,695
193+
Pretty cool, but the magic of
194+
Vue starts when data changes.
195+
196+
44
197+
00:01:50,695 --> 00:01:51,975
198+
If we jump into the console,
199+
200+
45
201+
00:01:51,975 --> 00:01:54,735
202+
we change the value of our product.
203+
204+
46
205+
00:01:54,735 --> 00:01:57,324
206+
Notice that as soon as the
207+
value of product changed,
208+
209+
47
210+
00:01:57,324 --> 00:01:59,953
211+
Vue automatically updated our HTML.
212+
213+
48
214+
00:01:59,953 --> 00:02:01,745
215+
This is because Vue is reactive,
216+
217+
49
218+
00:02:01,745 --> 00:02:03,273
219+
meaning that when our data changes,
220+
221+
50
222+
00:02:03,273 --> 00:02:05,193
223+
Vue takes care of updating all the places
224+
225+
51
226+
00:02:05,193 --> 00:02:07,255
227+
we're using it in our web page.
228+
229+
52
230+
00:02:07,255 --> 00:02:10,305
231+
This works with any kind
232+
of data, not just strings.
233+
234+
53
235+
00:02:10,305 --> 00:02:11,604
236+
So instead of a single product,
237+
238+
54
239+
00:02:11,604 --> 00:02:14,604
240+
let's use an array of products.
241+
242+
55
243+
00:02:14,604 --> 00:02:17,865
244+
Then we'll update our
245+
H2 to an unordered list,
246+
247+
56
248+
00:02:17,865 --> 00:02:20,535
249+
and create a new list item
250+
for each product in the array
251+
252+
57
253+
00:02:20,535 --> 00:02:22,618
254+
using Vue's v-for directive.
255+
256+
58
257+
00:02:24,353 --> 00:02:26,615
258+
This way, each product
259+
gets its own list item
260+
261+
59
262+
00:02:26,615 --> 00:02:28,495
263+
as you see here.
264+
265+
60
266+
00:02:28,495 --> 00:02:30,352
267+
This is still a little contrived though.
268+
269+
61
270+
00:02:30,352 --> 00:02:32,312
271+
So let's start with our list empty
272+
273+
62
274+
00:02:32,312 --> 00:02:34,815
275+
and fetch our products from an actual API
276+
277+
63
278+
00:02:34,815 --> 00:02:37,433
279+
which could be coming
280+
from a database somewhere.
281+
282+
64
283+
00:02:37,433 --> 00:02:38,863
284+
When our app is created,
285+
286+
65
287+
00:02:38,863 --> 00:02:41,866
288+
we'll fetch the latest
289+
products from this API.
290+
291+
66
292+
00:02:41,866 --> 00:02:43,199
293+
All you need to take from it is that
294+
295+
67
296+
00:02:43,199 --> 00:02:45,063
297+
we're fetching our list of products
298+
299+
68
300+
00:02:45,063 --> 00:02:46,923
301+
and updating them in our data.
302+
303+
69
304+
00:02:46,923 --> 00:02:48,281
305+
As you can see on our web page,
306+
307+
70
308+
00:02:48,281 --> 00:02:51,435
309+
each list item is showing
310+
the object it returned.
311+
312+
71
313+
00:02:51,435 --> 00:02:53,474
314+
Well, it's not human readable yet,
315+
316+
72
317+
00:02:53,474 --> 00:02:56,265
318+
so let's change the way it's displayed.
319+
320+
73
321+
00:02:56,265 --> 00:02:59,643
322+
We'll print out quantity and name.
323+
324+
74
325+
00:02:59,643 --> 00:03:02,265
326+
And there it is, printing out nicely.
327+
328+
75
329+
00:03:02,265 --> 00:03:03,563
330+
We might want to call attention to the
331+
332+
76
333+
00:03:03,563 --> 00:03:05,675
334+
items that have quantity zero.
335+
336+
77
337+
00:03:05,675 --> 00:03:09,595
338+
So let's add a little span
339+
with the text, out of stock.
340+
341+
78
342+
00:03:09,595 --> 00:03:13,334
343+
This should only appear if
344+
our item quantity equals zero.
345+
346+
79
347+
00:03:13,334 --> 00:03:16,134
348+
We're going to use the v-if directive.
349+
350+
80
351+
00:03:16,134 --> 00:03:20,362
352+
Because our jacket has quantity
353+
of zero, it's out of stock.
354+
355+
81
356+
00:03:20,362 --> 00:03:22,081
357+
What if we wanted to
358+
print out the total number
359+
360+
82
361+
00:03:22,081 --> 00:03:24,641
362+
of products under our list?
363+
364+
83
365+
00:03:24,641 --> 00:03:26,468
366+
To make this work, we need to create
367+
368+
84
369+
00:03:26,468 --> 00:03:29,570
370+
a computed property called totalProducts
371+
372+
85
373+
00:03:29,570 --> 00:03:34,228
374+
which returns the total
375+
quantity of our products.
376+
377+
86
378+
00:03:34,228 --> 00:03:36,490
379+
If you're not familiar
380+
with JavaScript reduce,
381+
382+
87
383+
00:03:36,490 --> 00:03:40,468
384+
it's adding up all the
385+
quantities from each product.
386+
387+
88
388+
00:03:40,468 --> 00:03:41,851
389+
As you can see, over in our browser,
390+
391+
89
392+
00:03:41,851 --> 00:03:45,308
393+
it's properly adding
394+
up all the quantities.
395+
396+
90
397+
00:03:45,308 --> 00:03:47,588
398+
Here in the browser, I
399+
want to show you Vue's
400+
401+
91
402+
00:03:47,588 --> 00:03:51,380
403+
Chrome plugin where we
404+
can see our array of data
405+
406+
92
407+
00:03:51,380 --> 00:03:53,547
408+
and inspect it right here.
409+
410+
93
411+
00:03:55,108 --> 00:03:57,460
412+
Since we're in the console, just for fun,
413+
414+
94
415+
00:03:57,460 --> 00:03:59,850
416+
let's pop the last item out of the array
417+
418+
95
419+
00:03:59,850 --> 00:04:01,828
420+
and see what happens.
421+
422+
96
423+
00:04:01,828 --> 00:04:04,359
424+
As you can see, not only
425+
is our list updated,
426+
427+
97
428+
00:04:04,359 --> 00:04:07,940
429+
but our total as well, as you would hope.
430+
431+
98
432+
00:04:07,940 --> 00:04:10,410
433+
Next, let's add some
434+
interactivity to this page
435+
436+
99
437+
00:04:10,410 --> 00:04:12,346
438+
through the use of a button.
439+
440+
100
441+
00:04:12,346 --> 00:04:14,490
442+
We'll create an add
443+
button for each product
444+
445+
101
446+
00:04:14,490 --> 00:04:15,850
447+
and when a click occurs,
448+
449+
102
450+
00:04:15,850 --> 00:04:18,850
451+
we'll increment the quantity by one.
452+
453+
103
454+
00:04:19,959 --> 00:04:22,279
455+
Back in the browser, notice
456+
how when we add an item,
457+
458+
104
459+
00:04:22,279 --> 00:04:25,159
460+
not only does the total
461+
inventory get updated,
462+
463+
105
464+
00:04:25,159 --> 00:04:27,780
465+
but also if we increment
466+
our jacket product,
467+
468+
106
469+
00:04:27,780 --> 00:04:30,300
470+
our out of stock notice goes away.
471+
472+
107
473+
00:04:30,300 --> 00:04:31,860
474+
Clicking this button a million times
475+
476+
108
477+
00:04:31,860 --> 00:04:33,890
478+
is going to get tiring,
479+
so what if we wanted to
480+
481+
109
482+
00:04:33,890 --> 00:04:37,719
483+
write in the quantity of
484+
jackets or hiking socks?
485+
486+
110
487+
00:04:37,719 --> 00:04:40,580
488+
We just create a new input
489+
field and bind it to our
490+
491+
111
492+
00:04:40,580 --> 00:04:43,867
493+
product quantity field
494+
with the v-model directive
495+
496+
112
497+
00:04:43,867 --> 00:04:46,519
498+
specifying that it is always a number.
499+
500+
113
501+
00:04:46,519 --> 00:04:48,060
502+
You'll notice now, I can input the total
503+
504+
114
505+
00:04:48,060 --> 00:04:52,450
506+
quantity of each item and
507+
it gets updated immediately.
508+
509+
115
510+
00:04:52,450 --> 00:04:54,500
511+
I can even set the quantity back to zero
512+
513+
116
514+
00:04:54,500 --> 00:04:57,899
515+
and I get my out of stock statement.
516+
517+
117
518+
00:04:57,899 --> 00:05:01,232
519+
And my add buttons still work just fine.
520+
521+
118
522+
00:05:02,259 --> 00:05:03,999
523+
If we were building a larger application,
524+
525+
119
526+
00:05:03,999 --> 00:05:05,839
527+
we might want to split
528+
things up at this point
529+
530+
120
531+
00:05:05,839 --> 00:05:09,290
532+
into their own components and files.
533+
534+
121
535+
00:05:09,290 --> 00:05:11,827
536+
Vue even has a command line interface
537+
538+
122
539+
00:05:11,827 --> 00:05:15,828
540+
which makes it simple to
541+
start real projects quickly.
542+
543+
123
544+
00:05:15,828 --> 00:05:18,879
545+
We might even use single
546+
file Vue components
547+
548+
124
549+
00:05:18,879 --> 00:05:21,770
550+
which contain their own HTML, JavaScript,
551+
552+
125
553+
00:05:21,770 --> 00:05:23,687
554+
and Scoped CSS, or SCSS.
555+
556+
126
557+
00:05:25,599 --> 00:05:28,926
558+
- Hi, I'm Evan You, the creator of Vue.js.
559+
560+
127
561+
00:05:28,926 --> 00:05:31,587
562+
What you've seen here
563+
barely scratched the surface
564+
565+
128
566+
00:05:31,587 --> 00:05:33,065
567+
of what Vue can do.
568+
569+
129
570+
00:05:33,065 --> 00:05:34,856
571+
There's so much more in the ecosystem
572+
573+
130
574+
00:05:34,856 --> 00:05:36,555
575+
to help you build, organize,
576+
577+
131
578+
00:05:36,555 --> 00:05:39,076
579+
and scale your frontend applications.
580+
581+
132
582+
00:05:39,076 --> 00:05:42,457
583+
To get a better taste, read
584+
our documentation today.
585+
586+
133
587+
00:05:42,457 --> 00:05:44,708
588+
I think you'll enjoy the View.

0 commit comments

Comments
 (0)
Please sign in to comment.