Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
WEBVTT
00:01.020 --> 00:02.910
In view 3.2.
00:02.940 --> 00:09.930
A new syntax or pattern for the composition API was introduced, which is the script set-top pattern.
00:10.110 --> 00:16.110
All syntax scripts set up allows us to make our components a lot simpler, less cluttered and easier
00:16.110 --> 00:22.680
to manage, and allows us to get rid of the export default, get rid of the set up function, and most
00:22.680 --> 00:25.240
importantly, get rid of the return statement.
00:25.260 --> 00:30.600
So with the script set up, we no longer need to worry about making sure all of our data properties,
00:30.600 --> 00:33.870
methods, computed properties, etc. are returned.
00:33.900 --> 00:38.660
Now, on a simple component like this, it might not make much difference, but in a really complicated
00:38.660 --> 00:44.310
set up with hundreds of components which each have tons of different data properties, methods, watches,
00:44.310 --> 00:50.070
computed properties, etc. It really makes our life easier not having to constantly keep this return
00:50.070 --> 00:56.850
statement updated every time we change any of our data properties, methods or rename them etc. for
00:56.850 --> 00:59.370
my own Fujitsu to which I'm currently working on.
00:59.430 --> 01:06.210
I actually spent a whole day converting around 100 components from this setup function pattern to the
01:06.210 --> 01:07.710
new script set-top pattern.
01:07.740 --> 01:12.660
And that was a really boring day, but it was well worth it because now the app is much easier to work
01:12.660 --> 01:12.860
on.
01:12.870 --> 01:17.310
And by the way, the script setter pattern is the pattern I'm going to be using for the rest of the
01:17.310 --> 01:21.520
course because it's much simpler and is the pattern that the team recommends.
01:21.540 --> 01:24.840
So let's convert this code to the new script set top pattern.
01:25.170 --> 01:27.990
So I'm going to commence out this script section.
01:29.650 --> 01:33.270
I'm allowed a new script section here.
01:34.440 --> 01:39.350
Now, we don't need to add our export default and we don't need to add this setup function.
01:39.360 --> 01:45.690
All we need to do is add a set of attributes to this opening script like this, and we can now place
01:45.720 --> 01:51.330
all of our code in here, all of our data properties, methods, etc., and we don't even need to return
01:51.330 --> 01:52.110
any of these.
01:52.110 --> 01:57.270
So let's just copy our two methods and our accounts are ref from the old code.
01:58.800 --> 02:05.700
Paste it straight in here, just fix the indentation and we still need to import this method from view,
02:05.730 --> 02:06.720
so I'll copy that.
02:07.350 --> 02:12.750
We just place all of our imports at the top of this script section like this, and now we don't need
02:12.750 --> 02:15.360
to return our data or our methods.
02:15.600 --> 02:18.330
Any data, properties or methods are computed.
02:18.330 --> 02:24.480
Properties that we declare at the top level of this script will be available in our template automatically.
02:24.480 --> 02:32.070
So if I save this now, it should just be working straight away, and yet it's still working and we've
02:32.070 --> 02:36.330
now reduced our script section from, let's say.
02:38.330 --> 02:39.560
21 lines.
02:40.470 --> 02:41.430
Down to.
02:43.400 --> 02:44.850
Just 11 lines.
02:44.870 --> 02:50.360
So we've massively simplified our code and we no longer need to worry about this pesky return statement.3681
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.