These integration guides are not official documentation and the Strapi Support Team will not provide assistance with them.
Strapi is the leading open-source headless CMS offering features, like customizable APIs, role-based permissions, multilingual support, etc. It simplifies content management and integrates effortlessly with modern frontend frameworks.
Explore the Strapi documentation for more details.
Vue.js is a JavaScript framework for building user interfaces. It builds on top of standard HTML, CSS, and JavaScript and provides a declarative, component-based programming model that helps you efficiently develop user interfaces of any complexity.
Visit the Vue.js documentation for more.
The out-of-the-box Strapi features allow you to get up and running in no time: 1. Single types: Create one-off pages that have a unique content structure 2. Customizable API: With Strapi, you can just hop in your code editor and edit the code to fit your API to your needs. 3. Integrations: Strapi supports integrations with Cloudinary, SendGrid, Algolia, and others. 4. Editor interface: The editor allows you to pull in dynamic blocks of content. 5. Authentication: Secure and authorize access to your API with JWT or providers. 6. RBAC: Help maximize operational efficiency, reduce dev team support work, and safeguard against unauthorized access or configuration modifications. 7. i18n: Manage content in multiple languages. Easily query the different locales through the API.
Learn more about Strapi features.
We are going to start by setting up our Strapi 5 project with the following command:
🖐️ Note: make sure that you have created a new directory for your project.
You can find the full documentation for Strapi 5 here.
npx create-strapi-app@latest server
You will be asked to choose if you would like to use Strapi Cloud we will choose to skip for now.
Strapi v5.6.0 🚀 Let's create your new project
We can't find any auth credentials in your Strapi config.
Create a free account on Strapi Cloud and benefit from:
- ✦ Blazing-fast ✦ deployment for your projects
- ✦ Exclusive ✦ access to resources to make your project successful
- An ✦ Awesome ✦ community and full enjoyment of Strapi's ecosystem
Start your 14-day free trial now!
? Please log in or sign up.
Login/Sign up
❯ Skip
After that, you will be asked how you would like to set up your project. We will choose the following options:
? Do you want to use the default database (sqlite) ? Yes
? Start with an example structure & data? Yes <-- make sure you say yes
? Start with Typescript? Yes
? Install dependencies with npm? Yes
? Initialize a git repository? Yes
Once everything is set up and all the dependencies are installed, you can start your Strapi server with the following command:
cd server
npm run develop
You will be greeted with the Admin Create Account screen.
Go ahead and create your first Strapi user. All of this is local so you can use whatever you want.
Once you have created your user, you will be redirected to the Strapi Dashboard screen.
Since we created our app with the example data, you should be able to navigate to your Article collection and see the data that was created for us.
Now, let's make sure that all of the data is published. If not, you can select all items via the checkbox and then click the Publish button.
Once all your articles are published, we will expose our Strapi API for the Articles Collection. This can be done in Settings -> Users & Permissions plugin -> Roles -> Public -> Article.
You should have find
and findOne
selected. If not, go ahead and select them.
Now, if we make a GET
request to http://localhost:1337/api/articles
, we should see the following data for our articles.
🖐️ Note: that article covers (images) are not returned. This is because the REST API by default does not populate any relations, media fields, components, or dynamic zones.. Learn more about REST API: Population & Field Selection.
So let's get the article covers by using the populate=*
parameter: http://localhost:1337/api/articles?populate=*
Nice, now that we have our Strapi 5 server setup, we can start to setup our Vue.js application.
Create a basic Vue.js application using the command below. This command will install and execute create-vue
, the official Vue project scaffolding tool.
npm create vue@latest
After running the command above, you will prompted with the following. Your answers will depend on your preferred setup.
✔ Project name: … vue-project
✔ Add TypeScript? … No / Yes
✔ Add JSX Support? … No / Yes
✔ Add Vue Router for Single Page Application development? … No / Yes
✔ Add Pinia for state management? … No / Yes
✔ Add Vitest for Unit Testing? … No / Yes
✔ Add an End-to-End Testing Solution? › No
✔ Add ESLint for code quality? › No
Once your project is created, run the command below to install dependencies and start the dev server:
cd <your-project-name>
npm install
npm run dev
You should now have your first Vue project running on "http://localhost:5173" as shown below:
We will install Tailwind CSS as a PostCSS plugin. This is the most seamless way.
Run the command below:
npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init
The command above will create a Tailwind CSS configuration file called tailwind.config.js
.
Create a configuration file called postcss.config.cjs
at the root of your project and add the following code:
1// Path: ./postcss.config.cjs
2
3module.exports = {
4 plugins: {
5 tailwindcss: {},
6 autoprefixer: {},
7 }
8}
Add the paths to all of your template files:
1// Path: ./tailwind.config.js
2
3/** @type {import('tailwindcss').Config} */
4module.exports = {
5 content: ['./index.html', './src/**/*.{vue,js,ts,jsx,tsx}'],
6 theme: {
7 extend: {
8 },
9 },
10 plugins: [],
11}
Inside the ./src/assets/main.css
file, replace the code with the following code:
1/** Path: ./src/assets/main.css **/
2
3@tailwind base;
4@tailwind components;
5@tailwind utilities;
After Tailwind CSS setup, ensure you restart your application.
npm run dev
Many HTTP clients are available, but on this integration page, we'll use Axios and Fetch.
Install Axios by running any of the commands below:
# npm
npm i axios
# yarn
yarn add axios
No installation needed
Execute a GET
request on the Article collection type in order to fetch all your articles.
Be sure that you activated the find
permission for the Article
collection type.
🖐️ NOTE: We want to also fetch covers (images) of articles, so we have to use the
populate
parameter as seen below.
1import axios;
2
3// fetch articles along with their covers
4const response = await axios.get("http://localhost:1337/api/articles?populate=*");
5console.log(response.data.data);
1const response = await fetch("http://localhost:1337/api/articles?populate=*");
2const data = await response.json();
3console.log(data.data);
Inside the ./src/App.vue
, we will be using the Composition API. Check out Vue.js API styles to learn more.
Add the following to the <script setup>
section:
1// Path: ./src/App.vue
2
3<script setup>
4// Import dependencies
5import { ref, onMounted } from "vue";
6
7// Variables
8const articles = ref([]);
9
10// Strapi Base URL
11const STRAPI_URL = "http://localhost:1337" || import.meta.env.VITE_STRAPI_URL;
12
13// Fetch articles
14const getArticles = async () => {
15 const response = await fetch(`${STRAPI_URL}/api/articles?populate=*`);
16 const data = await response.json();
17 articles.value = data.data;
18};
19
20// Format date
21const formatDate = (date) => {
22 const options = { year: "numeric", month: "2-digit", day: "2-digit" };
23 return new Date(date).toLocaleDateString("en-US", options);
24};
25
26// Fetch articles on component mount
27onMounted(() => {
28 getArticles();
29});
30</script>
Here is what we did above:
ref
and onMounted
are imported from Vue for managing reactive state and lifecycle hooks, respectively.articles
reactive variable initialized as an empty array. This will store the articles fetched from the Strapi API.STRAPI_URL
Defines the base URL for the Strapi API. It falls back to "http://localhost:1337" by default but allows for environment configuration using import.meta.env.VITE_STRAPI_URL
.getArtices
: An asynchronous function that fetches articles from Strapi. It sends a request to the Strapi API's /api/articles?populate=*
endpoint, which retrieves all articles along with their associated media (images). The response is parsed into JSON, and the article data is assigned to the articles
reactive variable.formatDate
function formats the publishedAt
date of each article into a human-readable string (e.g., 01/14/2025). It uses the toLocaleDateString
method with options to display the year, month, and day in a MM/DD/YYYY
format.onMounted
hook ensures that the getArticles
function is called once the component is mounted to the DOM. This is when the data is fetched from Strapi.<template>
This section defines the structure and layout of the UI, utilizing Tailwind CSS classes for styling.
1// Path: ./src/App.vue
2
3<template>
4 <div class="p-6">
5 <h1 class="text-4xl font-bold mb-8">Vue.js and Strapi Integration</h1>
6 <div>
7 <h2 class="text-2xl font-semibold mb-6">Articles</h2>
8 <div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6">
9 <article
10 v-for="article in articles"
11 :key="article.id"
12 class="bg-white shadow-md rounded-lg overflow-hidden"
13 >
14 <img
15 :src="STRAPI_URL + article.cover.url"
16 alt="Article Image"
17 class="w-full h-48 object-cover"
18 />
19 <div class="p-4">
20 <h3 class="text-lg font-bold mb-2">{{ article.title }}</h3>
21 <p class="text-gray-600 mb-4">{{ article.content }}</p>
22 <p class="text-sm text-gray-500">
23 Published: {{ formatDate(article.publishedAt) }}
24 </p>
25 </div>
26 </article>
27 </div>
28 </div>
29 </div>
30</template>
Now, this is what your Vue.js project should look like:
Awesome, great job!
You can find the complete code for this project in the following Github repo.
If you have any questions about Strapi 5 or just would like to stop by and say hi, you can join us at Strapi's Discord Open Office Hours Monday through Friday at 12:30 pm - 1:30 pm CST: Strapi Discord Open Office Hours
For more details, visit the Strapi documentation and Vue.js documentation.