All language subtitles for 004 Composition API - Data (refs) & Methods_en

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French Download
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranî)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: WEBVTT 00:00.840 --> 00:04.010 Let's set up a reactive data variable for our counter. 00:04.290 --> 00:08.270 Now in the composition API, there are two main types of reactive data. 00:08.280 --> 00:10.620 We have refs and reactive objects. 00:10.650 --> 00:13.970 I'll get into these in more detail later on in the course. 00:13.980 --> 00:20.490 But basically a reactive object allows us to create an object of data with a bunch of related data properties 00:20.490 --> 00:21.630 inside that object. 00:21.630 --> 00:28.410 Whereas a ref is generally used for simple single items of data such as a string, an array or a number. 00:28.440 --> 00:30.700 So it makes sense to use a ref for this. 00:30.720 --> 00:34.830 So to set up a graph, we can just create a constant and give it a name. 00:35.310 --> 00:39.030 Whatever name we use will be the name that's available in the template. 00:39.060 --> 00:43.470 So we're going to call this counter since that's the name we've used in our template here, and we want 00:43.470 --> 00:49.540 to set that equal to the ref method like this, and then we can pass our initial value inside this method. 00:49.560 --> 00:55.620 So let's set that to zero initially because we using this method, we need to import this method from 00:55.620 --> 01:02.790 view so above our export, we need to import ref from view. 01:02.940 --> 01:06.030 Now this counter ref is not available in our template yet. 01:06.240 --> 01:10.290 We also need to return it when we're using the setup function pattern. 01:10.300 --> 01:17.130 So right to the bottom of our setup function, we need to add a return statement on this return statement 01:17.130 --> 01:22.950 should always stay at the bottom of the setup function and then we just need to return this counter 01:22.950 --> 01:27.390 ref like this and save that and hopefully this counter should be hooked up. 01:27.390 --> 01:29.280 Now we can see zero on the page. 01:29.520 --> 01:33.930 If we change the value of this ref and save it, we can see it's updated on the template. 01:34.230 --> 01:36.950 We're going to set this back to zero and save that. 01:37.080 --> 01:37.410 Okay. 01:37.410 --> 01:41.910 We now need to add decrease counter and increase counter methods on the way we do. 01:41.910 --> 01:48.420 This is just by creating some named functions anywhere within this setup function and then we need to 01:48.420 --> 01:51.420 return them just like we return this counter. 01:51.660 --> 01:56.640 So let's create a method for increasing the counter so we can either do this like this with the function 01:56.640 --> 01:57.170 keyword. 01:57.390 --> 02:07.950 So function increase counter, or we can do a constant named increase counter, which we set equal to 02:07.980 --> 02:11.400 a function like this, which is the method that I usually use. 02:11.940 --> 02:16.680 So all we want to do is increase this counter ref by one and you might think we'd be able to just do 02:16.680 --> 02:18.360 counter plus plus. 02:18.360 --> 02:23.400 But actually this won't work with the composition API because when we create a ref they actually creates 02:23.400 --> 02:27.840 an object and the value of our ref is stored in a property called value. 02:28.260 --> 02:33.390 So to access this we actually need to do counter value and we can then do plus plus. 02:33.390 --> 02:38.070 And again in order to use this method in our template, we need to return it so we can just added to 02:38.070 --> 02:44.760 this return object like this increase counter since we already have a click color here which is firing 02:44.760 --> 02:46.770 the same method and this should work. 02:46.770 --> 02:50.610 So I'll save that click on the plus button and that's working. 02:51.300 --> 02:54.150 So now we just need to create the decrease counter method. 02:54.660 --> 03:01.560 So I'll duplicate this increase counter method, rename it to decrease counter and just change the plus 03:01.560 --> 03:05.760 plus to minus minus so that it decreases the accounts of value by one. 03:05.940 --> 03:07.620 And again, we need to return this. 03:08.160 --> 03:14.370 So we'll add it to our return statement down here, decrease counter, save that and hopefully both 03:14.370 --> 03:15.330 buttons should be working. 03:17.140 --> 03:18.670 And yeah, everything is working.4513

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.