Was this article helpful?
Thanks for your feedback
Nuxt.js is a Vue.js framework used to build modern web applications. This example website is built on top of Nuxt.js and uses Contentstack’s Node.js SDK. It uses Contentstack to store and deliver the content of the website.
Here’s a quick guide on how to create this demo website using Nuxt.js and Contentstack.
Note: For this tutorial, we have assumed that you are familiar with Contentstack and Nuxt.js. If not, then please refer to the docs (Contentstack docs and Nuxt.js docs) for more details.
In this tutorial, we will first go through the steps involved in configuring Contentstack, and then look at the steps required to customize and use the presentation layer.
Log in to your Contentstack account, and create a new stack. This stack will hold all the data, specific to your website. Learn more on how to create a stack.
To add an environment in Contentstack, navigate to ‘Settings' -> 'Environment', and click on the '+ New Environment’ tab. Provide a suitable name for your environment, say ‘staging’. Specify the base URL (e.g., ‘http://YourDomainName.com’), and select the language (e.g., English - United States). Then, click on 'Save'. Read more about environments.
A content type is like the structure or blueprint of a page or a section of your web or mobile property. Read more about Content Types.
For this website, three basic content types are required: Header, Footer, and Home. For quick integration, we have already created these content types. You simply need to import them to your stack. (You can also create your own content types. Learn how to do this).
To import the content types, first save the zipped folder of the JSON files given below on your local machine. Extract the files from the folder. Then, go to your stack in Contentstack. The next screen prompts you to either create a new content type or import one into your stack. Click the ‘Import’ link, and select the JSON file saved on your machine.
Note: Import JSON files in the sequence: 'header.json', 'footer.json', and 'home.json'.
Here’s a brief overview of all the content types required for this project.
Now that all the content types are ready, let’s add some content for your website.
Create and publish entries for the ‘Header’ and ‘Footer’ content types
Using the ‘Header’ content type, add the menu details for your website. Similarly, add footer content using the ‘Footer’ content type. Learn how to create and publish entries.
Create and publish entry for the ‘Home’ content type
Add an entry for the ‘Home’ content type. The ‘Home’ content type includes two reference fields: ‘Header’ and ‘Footer’. You need to select the respective entries in these fields. Save and publish the entry. Learn how to create and publish entries.
With this step, you have created sample data for your website.
Since Contentstack is a headless CMS, the content created and saved in it can be consumed by any platform, any channel, anywhere. You can create your custom presentation layer, and deliver content to your website/app through Contentstack. To get your app up and running quickly, we have created a sample website (using Node.js, Nuxt.js) for this project. You simple need to download it and change the configuration.
Note: The website uses the Content Delivery API (which has in-built CDN support) to deliver content to the website. Read more about our CDN-enabled content delivery system.
Once you have downloaded the project, add your Contentstack API Key, Delivery Token, and Environment to the project. (Learn how to find your Stack's API Key and Delivery Token. Read more about Environments.)
The nuxt.config.js file would look something like this:
env: { api_key: "Your API key", delivery_token: "Your Delivery Token", environment: "Your Publishing Environment", },
Note: Mention the environment name that you created in Contentstack.
Fire up your terminal (command prompt or similar on Windows), point it to your project location and run the following:
npm install npm run dev
Note: This will work on node version 6.9.0 or above.
Now open http://localhost:3000 to see your website. This will initiate your project.
You can make the application live by deploying it on any cloud-hosting service. In this tutorial, we have used Heroku as the hosting service.
Deploying your application on Heroku is quick and easy. If you are new to Heroku, refer to these steps to deploy your app.
This tutorial is an example of how you can use Contentstack SDK with Vue.js. Unlike the case with contentstack-express, routing is not handled automatically. You will need to add routing for your project by performing the steps given below.
You can refer an example of routing.
In your case, for '/home', you will need to create a separate route for 'home' under pages.
Once routes are created, you can create content types and entries for the pages of your project.
Additional Resource: Next.js is a framework used for server-rendered applications. To know how to use Next.js to build a website, be sure to read our documentation on how to build a website using Next.js and Contentstack.
Was this article helpful?
Thanks for your feedback