CRUD – Create, Read, Update, Delete I assume that you already know the fundamentals of Vue JS and/or you are a bit familiar with the framework. Nuxt JS is a robust framework, built on Vue JS. It is essentially the same as Vue JS. Then why, Nuxt? For most people, the decision to use Nuxt JS is usually for its SSR capabilities.

What is SSR?

SSR is an abbreviation for Server Side Rendering. Usually, for most Single Page Applications (SPA), rendered files are auto injected into the DOM after the page has loaded. Hence, bots, SEO crawlers will find an empty page on page load. However, for SSR, due to its ability to pre-render apps on the server before page, that page can be easily indexed by SEO crawlers. Also, it possibly makes the app even more performant than a regular SPA. Nuxt JS gives developers the ability to create SSR applications with ease. Regular Vue JS SPA apps can also be configured to use SSR, but the process is somewhat cumbersome, and Nuxt JS provides a wrapper to handle all of that configuration. Asides the SSR, Nuxt also provides an easy way to set up your VueJS project with more efficiency. Although Nuxt JS is still Vue JS, it has some fundamental differences in how its folder architecture is structured.

The focus of this article is for you to be able to build an app with Nuxt; hence, we aren’t going to dive deep into Nuxt’s folder architecture, however, I will quickly explain some of the important ones we might require here.

Pages

The pages folder is one of the fundamental differences from regular Vue SPA. It represents the Views folder in regular Vue architecture, mores o, in Nuxt, files created in the Pages folder are automatically provisioned as a route. Meaning, when you create an index.vue file in the pages folder, that automatically becomes your root route, i.e., localhost:3000/. Also, when you create any other filename.vue, it becomes a route — creating about.vue allows you access localhost:3000/about. You can also create a folder within the Pages folder. If you create a folder named ‘contact’ and within that folder, you have email.vue, then you can access localhost:3000/contact/email. It is that simple. This way, you don’t need to manually create a router.js file as you would typically do with Vue JS to create your routes.

Components

It’s still pretty much the same as with Vue JS, components created are not automatically provisioned as routes.

Static

Static folder replaces the public folder in regular Vue JS apps, functions pretty much the same. Files here do not get compiled; they are served the same way they are stored. You can read all about the architecture and structure at the Nuxt JS documentation page. Now, Let’s build something interesting…

Building a book store app

We will be building a book store app, where a user can add books they have read to a particular category they like. It will look like this.

So, we will have a simple layout as above, just 3 columns containing the different sections of books. Recently read books, favorite books, and yeah, best of the best books (I ‘ll confess, I didn’t know what to call that section, 🙂 ) So the goal here, is to be able to add a book’s title, author and description to a card on any of the sections, edit already added books and remove an existing book. We will not be utilizing any database, so everything happens in the state. First, we install Nuxt: Second, after installing Nuxt, you can now create the project with the command, I choose to name my app ‘bookStore’; you can name your something cooler ^_^ Then, let’s walk through the remaining prompts, enter a description,

Author name, type a name or press enter to retain defaults

Select a package manager, whichever you are comfortable with, both are fine

Select a UI framework. For this project, I will be using Vuetify, then again, any UI framework you are comfortable with will do just fine.

Select a custom server framework; we don’t need any, I ‘ll select none

Extra modules, select what you want, or select both, we wouldn’t be using them for this app.

Linting is important. Let’s go with ESLint.

While testing is important, we will not be looking at that today, so none

Rendering mode, yeah SSR it is. Note: Choosing SSR doesn’t mean we don’t get the benefit of having a SPA, the app still remains a SPA but with SSR. The other option means simply SPA and no SSR.

Hit enter and move on,

And our project is creating,

After creation, we can now go into the directory and run if you are using npm as your package manager, use,

By default, the app runs at localhost:3000. Visit the link in your browser, and you should see a default Nuxt page. Now let’s begin with creating components we need. We will have cards displaying each book information, and we will have a modal containing a form to enter new book information or edit existing ones. To create a component, simply create a new file in the components folder. Here is the code for my card component. A quick explanation of what is done above. The image is hardcoded; we will not bother about that for now. The book title, book author, and book description are passed down to this component from the parent page as props. If you are not familiar with props, imagine them as entry points through with this component can be populated with data. Now to the next component, the modal. Now, that is the markup for the modal; we need to create the v-models as data properties; therefore, we will add a script tag below the