It’s a good idea to use Bootstrap to add some styling and icons to our application, for that we need to add the following lines of code to our main HTML file, in the <head>
section:
<link rel="stylesheet" href="https://bootswatch.com/4/lux/bootstrap.min.css">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
So go ahead and open up the index.html
file in the src
folder and update it as below:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<title>Composition-Todo</title>
<link rel="stylesheet" href="https://bootswatch.com/4/lux/bootstrap.min.css">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body>
<noscript>
<strong>We're sorry but Composition-Todo doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>
Now we come to the main feature – using the composition API to build our application. The key benefit of this API is enhanced maintainability of your code by keeping logical concerns grouped together instead of being split up across component options like data, props, methods, etc.
While the benefits are not immediately apparent in our simple TODO application, imagine a more complex application where logic for different capabilities would normally be split across the file – the more your application grows in complexity, the harder it becomes to read and maintain.
As a comparison, we’ve shown how this component would be implemented with both the Options API and the Composition API – please copy the composition version into the
<script>
section of your
app.vue
file.