Create a simple house plant tracker with Contentful and Vue.js.
Follow the steps mentioned below to set up and run the project quickly. For more detailed instructions, follow the steps mentioned in Configuration.
First, create an account on Contentful.
After creating an account, create a new empty space from the dashboard and assign to it any name of your liking.
Access the source code by cloning this repository.
git clone https://github.com/contentful/starter-vue-tracker.git
Or by downloading as a zip file.
Once downloaded, in your terminal run
npm install
The starter comes with a Contentful set up command that imports the required content model and adds sample content to your space.
The command asks you for a Space ID, Content Management API Access Token, and the Content Delivery API Access Token.
In your terminal, navigate in to the project directory. Run the following command to set up the content model.
npm run setup
When prompted, enter the above mentioned details in the terminal respectively.
Execute the following command.
npm run dev
Navigate to localhost:5173
to view the site.
First, create an account on Contentful.
After creating an account, create a new empty space from the dashboard and assign to it any name of your liking.
The content model defines the data structures of your application/websites. The structures are flexible and you can tailor them to your needs.
For this example you need to create a content model that defines a plant. You can create them automatically by using this starter or by doing it manually to familiarize yourself with the Contentful user interface.
Plant
content typeFrom your Contentful space, go to Content model and add a new content type:
Plant
, the Api Identifier should be plant
Once the content model is saved, add these fields (you don't have to modify the settings unless specified):
Common Name
- Text field (type short text).
Scientific Name
- Rich Text field.Image
- Media field.Last Watered
- Date & time field.Watering Schedule
- Short Text field.Sunlight
- Short Text field.Happiness
- Boolean field.Save the content type and continue.
After setting up the content model, it should look as follows.
Content model overview
Go to the Content section in your space, then click on Add entry and select the Plant content type:
Important: For each entry and asset, you need to click on Publish. If not, the entry will be in draft state.
From your contentful space, go to Settings > API keys. Create a new API key.
If you ran npm run setup
a .env
file was created for you. If not, create a .env
file (which will be ignored by Git):
Then set each variable in .env
:
VITE_CONTENTFUL_SPACE_ID
should be the Space ID field of your API KeyVITE_CONTENTFUL_ACCESS_TOKEN
should be the Content Delivery API - access token field of your API keyYour .env
file should look like this:
VITE_CONTENTFUL_SPACE_ID=...
VITE_CONTENTFUL_ACCESS_TOKEN=...
npm install
npm run dev
Your app should be up and running on http://localhost:5173!
To deploy, run the following command and commit your changes to GitHub.
npm run build
Chose your favorite hosting provider such as Netlify or Vercel and create a new project.
NOTE: You'll have to configure the VITE_CONTENTFUL_SPACE_ID and VITE_CONTENTFUL_ACCESS_TOKEN values.