Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
WEBVTT
00:00.410 --> 00:06.830
We can see that refs are handy for storing simple independent items of data such as a number or a string,
00:07.160 --> 00:09.020
or maybe an array or a boolean.
00:09.050 --> 00:15.160
But what if we want to store a bunch of different data that's related together in a single object,
00:15.170 --> 00:18.200
a bit like we did with the data method in Options API?
00:18.620 --> 00:21.120
Well, we can do that with a reactive object.
00:21.140 --> 00:26.750
So let's say we want to store a counter about counter title together in a single object.
00:26.900 --> 00:31.400
Since this data is related, then we can do that with a reactive object.
00:31.760 --> 00:38.330
So to set up a reactive objects, we can create a const or we can use a variable and we give that name
00:38.330 --> 00:43.940
so we could call that counter data and we set that equal to the reactive method.
00:44.150 --> 00:46.160
We do need to import this from view.
00:46.190 --> 00:53.570
So we can just add that to our import object here reactive and we can just pass an object into this
00:53.570 --> 00:54.650
reactive method.
00:55.230 --> 00:57.650
Now we can place all of our data properties in here.
00:57.800 --> 01:03.020
So let's create a property called count for our count to give that an initial value of zero.
01:03.500 --> 01:10.040
And then without a property called title for the title, I will set that to my counter.
01:10.340 --> 01:10.970
Save that.
01:11.450 --> 01:16.860
Let's use the data from this reactive object in our template instead of the data from these refs.
01:16.880 --> 01:23.000
So if we want to use the counter that's in this reactive objects here, we can just do counter data
01:23.000 --> 01:24.060
dot count.
01:24.440 --> 01:27.740
And if we want to use the title, it's in the reactive objects.
01:28.460 --> 01:33.620
And we can just change this in this heading type to counter data dot title.
01:33.860 --> 01:37.250
Let's update this V model as well to use this reactive object.
01:37.730 --> 01:45.140
So I'll set this V model to counter data, Dot's title and I'll save that and reload.
01:45.440 --> 01:47.210
Let's see if our title sucks up.
01:47.210 --> 01:47.630
Okay.
01:48.200 --> 01:48.440
Yeah.
01:48.440 --> 01:51.410
That's still working on the two way data binding.
01:51.410 --> 01:53.960
Still working as well on a counter is working.
01:53.960 --> 01:55.700
We could see zero displayed there.
01:56.010 --> 01:59.900
And if I change the value of counter data accounts, we can see it.
01:59.900 --> 02:00.440
Update.
02:00.470 --> 02:05.330
However, these buttons are not working and that's because these methods, the increase counter method
02:05.330 --> 02:10.970
and the decrease counter method are still manipulating this ref and not this count that's in our active
02:11.090 --> 02:11.750
object.
02:12.500 --> 02:14.070
So let's update these methods.
02:14.090 --> 02:21.290
So instead of counter dot value plus plus, we can just two counts of data, dot counts, plus plus.
02:21.770 --> 02:28.190
And then in the decrease counter method, we can just do counter data dot count, minus, minus.
02:28.550 --> 02:33.440
Note that we don't need to use dot value when we're using data that's in reactive objects.
02:33.440 --> 02:37.190
We just use the straight property name counter data accounts.
02:37.280 --> 02:39.350
Now let's say that and see if these buttons are working.
02:40.350 --> 02:41.910
And yet that's working again now.
02:42.000 --> 02:42.390
Okay.
02:42.390 --> 02:44.970
So we're no longer using these refs anymore.
02:45.010 --> 02:48.000
Our base coach shows us that by graying these out a little bit.
02:48.030 --> 02:49.680
So let's just comment these out.
02:51.380 --> 02:56.930
And since we no longer using this method from view, we can remove that from this import statement like.
02:56.930 --> 02:58.220
So save the.4093
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.