Ecommerce is no small undertaking. Aside from building a great customer experience on the frontend, you’ll also need to have the right setup to handle all cart, customer and order data, product information, etc…
In this tutorial, you’ll get a sneak peek into how it can be done!
In this tutorial, you’ll get set up with the necessary prerequisites for a great ecommerce experience. Vue.js is a great choice for a frontend framework because it’s open source, it has a component-based architecture, and it is reactive.
For the backend, you’ll learn how to use Medusa, an open source Node.js commerce engine that ships with all necessary ecommerce functionality including an easily navigatable admin system.
The full code for this Vue.js project is located in this GitHub repo. Below is a quick sneak peek of the final result.
What is Vue.js
Vue.js is an open source progressive JavaScript framework. It can be used to build a variety of types of apps, including websites, mobile apps, or desktop apps. This can be done by using Vue.js along with other platforms like Electron or Ionic.
Vue.js has been rising in popularity since it was first released due to its many advantages. It is easy to learn and use, with concise documentation and a smooth learning curve. It also has a tiny size, a reactive system, and a component-based, reusable architecture.
What is Medusa
Medusa is the #1 open source, Node.js commerce platform on GitHub. Its composable and headless architecture allows it to be incorporated with any tech stack to build cross-platform ecommerce stores, ranging from web to android and iOS applications.
Medusa allows developers to build scalable and maintainable ecommerce stores. It ships with many advanced ecommerce features such as an admin store dashboard, product configurations, manual orders, multi-currency support, and much more. Likewise, it easily integrates with different payment, CMS, and shipping options.
Please star if you like the tool 🌟
Prerequisites
Before you start, be sure you have Node.js version 14 or above.
Create a Server with Medusa Commerce Engine
To set up the Medusa server on your local machine, follow the steps outlined in the sections below.
Install Medusa CLI Tool
Medusa CLI can be installed using
orCopy to clipboardnpm
, but this tutorial usesCopy to clipboardyarn
. Run the following command to install the Medusa CLI:Copy to clipboardnpm
Create a New Medusa Store Server
To create a new Medusa store server, run the command below:
Note:
represents the project name; you can change yours to your preferred project name.Copy to clipboardmy-medusa-store
If you created a new Medusa project successfully, you should get a result similar to the screenshot below.
Test Your Medusa Server
To test your Medusa server, change to the newly created directory and run the
command using Medusa’s CLI:Copy to clipboarddevelop
You can test it by sending a request to
which lists the available products in your store.Copy to clipboardlocalhost:9000/store/products/
Medusa Admin Installation
To set up your Medusa Admin, follow the steps below.
- Clone the Medusa Admin repository:
- Run the command below to install all necessary dependencies:
- Test it:
By default, Medusa Admin runs on port
. You can go toCopy to clipboard7000
on your browser to access your admin page.Copy to clipboardlocalhost:7000
Since you included the
option while installing the Medusa server, a dummy admin user has been created. The email isCopy to clipboard--seed
, and the password isCopy to clipboardadmin@medusa-test.com
.Copy to clipboardsupersecret
With the Medusa Admin, you can create new products and collections for your store. You can also edit, unpublish, duplicate and delete products from the admin.
You can visit the User Guide to learn more about Medusa Admin.
Create a New Vue.js Project
The next thing is to create and set up a new Vue.js project for the ecommerce project. You can run this command to set up a new Vue.js project:
This command will install and execute create-vue, the official Vue project scaffolding tool. You will be presented with prompts for a number of optional features such as TypeScript and testing
support.
Ensure you choose the same option as the ones in the above screenshot.
Once the project is created, use the following commands to install the necessary dependencies:
Tailwind CSS Installation
Tailwind CSS is a CSS framework that allows you to effortlessly style your ecommerce storefront. In this tutorial, you’ll use Tailwind CSS in your Vue.js ecommerce storefront.
In the
directory, run the following command to install Tailwind CSS:Copy to clipboardvuejs-ecommerce
The above command will generate both the
andCopy to clipboardtailwind.config.js
files in your Vue.js project.Copy to clipboardpostcss.config.js
Configure Your Template Paths
In your
file, replace theCopy to clipboardtailwind.config.js
array with the following snippet:Copy to clipboardcontent
Add the Tailwind Directives to your CSS
Go to
and replace the entire code with the snippet below:Copy to clipboardsrc/assets/main.css
- The
layer handles things like reset rules or default styles applied to plain HTML elements.Copy to clipboardbase
- The
layer handles class-based styles that you want to be able to override with utilities.Copy to clipboardcomponents
- The
layer handles small, single-purpose classes that should always take precedence over any other styles.Copy to clipboardutilities
You can visit Tailwind CSS documentation to learn more.
Integrate Vue.js Ecommerce Storefront with Medusa
In this section, you’ll prepare to integrate the Vue.js ecommerce storefront with the Medusa server to interact with APIs later on.
Create a Base URL Environment Variable
The
environment variable is the URL of your Medusa server. Create aCopy to clipboardbaseURL
file in theCopy to clipboard.env
directory with the following content:Copy to clipboardvuejs-ecommerce
Note: If for any reason, you changed the default port number of your Medusa Server, you must change the
to your port number here.Copy to clipboard9000
Install Axios in the Vue.js Project
You’ll use Axios to send requests to your Medusa server. You can install Axios by running the following command:
Now that Axios is installed, the next step is integrating Medusa API into your project.
Creating Components for Your Vue.js Project
In this section, you will create components such as
,Copy to clipboardHeader
, andCopy to clipboardFooter
components. These components will be used on different pages of your storefront.Copy to clipboardProducts
In some components images are used to implement a better design for the storefront. You can find all images used for this project in the GitHub repository.
Page Header Component
Create the file
and add the following code to it:Copy to clipboardsrc/components/PageHeader.vue
The above code block covers the header page of this project. It includes the page routes, website name, and shopping cart icon.
This component will be added later in
of this project to add a header on every page of this storefront.Copy to clipboardsrc/App.vue
Footer Component
Create the file
with the following content:Copy to clipboardsrc/components/FooterComponent.vue
In the above component, you covered everything about the footer page of this ecommerce app. You’ll use it later across your pages where you want to add a footer.
Products Component
Create the file
with the following content:Copy to clipboardsrc/components/Products.vue
The product component is where the products are fetched using Medusa’s APIs.
method is used to fetch products from the Medusa Server. Notice how you use theCopy to clipboardfetchProducts
defined in theCopy to clipboardbaseURL
file.Copy to clipboard.env
In addition, the Vue router is being used to route each selected product to a single product page which you’ll add later.
Creating Vue.js Router File for Routing Pages
The next thing to do is to create a router file for routing our pages. By default, a route file is always generated when creating the vue.js project. Find the
file and replace the code inside with the below content:Copy to clipboardsrc/router/index.js
In the above component, you specified all your routes, including the route path, name, and components. The routes you added are for the homepage, products page, and single product page.
Create Storefront Pages
In this section, you’ll create pages for your storefront. Before you start creating these pages, go to
and replace the code with the following:Copy to clipboardsrc/App.vue
Here, you import the header component so that it appears on all pages.
You also add some methods related to the cart. The
method checks on page load if there’s a cart ID in the local storage, and if so calls theCopy to clipboardcheckCartID
method. TheCopy to clipboardgetCartID
method is used to fetch cart and its items from the Medusa server.Copy to clipboardgetCartID
The
method is used to add products to your store cart. It will be called later on the Single Product page.Copy to clipboardaddP
You can learn more about Medusa carts in the documentation.
Homepage View
Create the file
with the following content:Copy to clipboardsrc/views/HomeView.vue
You import the
andCopy to clipboardProducts
components inside this file and display them on the Homepage.Copy to clipboardFooterComponent
Products Page View
Create the file
with the following content:Copy to clipboardsrc/views/ProductView.vue
You also import the
andCopy to clipboardProducts
components inside this file to display them in the Products listing page.Copy to clipboardFooterComponent
Single Product Page
Create the file
with the following content:Copy to clipboardsrc/views/SingleProductView.vue
In the above code block, you are fetching a single product from the Medusa server using its id. Then, you display the product’s information including its price, size, and description.
When the Add to Cart button is clicked, the
method is executed. This method calls theCopy to clipboardaddProduct
method defined inCopy to clipboardaddP
passing it the selected variant ID.Copy to clipboardsrc/App.vue
Change Vue.js Port
In the
file, add this code snippet inside the object parameter passed toCopy to clipboardvite.config.js
:Copy to clipboarddefineConfig
In the above code block, you change the port of the Vue.js ecommerce storefront to
. This allows you to avoidCopy to clipboard8000
issues when sending requests to the Medusa server.Copy to clipboardcors
Test the Storefront
You can now test your Vue.js ecommerce storefront with the following steps:
- Run the Medusa server:
- Run the Vue.js app:
When you open the storefront on
, you’ll see the following home page:Copy to clipboardlocalhost:8000
If you scroll down or click on the Products item in the navigation bar, you’ll see products populated from your Medusa server.
Try clicking on any of the products, a new page will open showing the products details.
You can add the product to the cart by clicking the “Add to Cart” button.
What’s Next?
In this tutorial, you learned how to create a Vue.js Ecommerce storefront with the help of Medusa. This storefront only implements the product listing and add-to-cart functionality, but there’s much more to add to your storefront.
Check out the following documentation pages for help on how to move forward:
- Add a checkout page.
- Install Stripe plugin to process payments.
- Add advanced search functionality with MeiliSearch.
Should you have any issues or questions related to Medusa, then feel free to reach out to the Medusa team via Discord
Share this post
Try Medusa
Spin up your environment in a few minutes.

You may also like
On this page