Search⌘ K
AI Features

Build The Homepage

Explore how to create a functional homepage for your e-commerce app by displaying product categories and items using reusable Vue.js components. Understand structuring the template with assets and data imports for an engaging customer interface.

Start building the homepage

Right now, our homepage, Home.vue, is empty. It’s time to display some categories and products there.

We can save this image as “homepage.jpg” in the assets directory.

Let’s start building the homepage.

We’ll display the image at the top and display some categories and products at the bottom.

The script section

We’ll import baseURL, products, and categories from App.vue.

We’ll import ProductBox and CategoryBox from the components. That’s the power of component reusability.

We’ll display a maximum of six categories and eight products. Ideally, we should have another API that gives us the top products and categories with pagination. We might develop the API later.

C++
<script>
import ProductBox from "../components/Product/ProductBox";
import CategoryBox from "../components/Category/CategoryBox";
export default {
name: 'Home',
components : { ProductBox, CategoryBox},
props : ["baseURL", "products", "categories"],
data(){
return{
category_size:0,
product_size:0
}
},
mounted(){
this.category_size = this.categories.length;
this.category_size = Math.min(6, this.category_size);
this.product_size = this.products.length;
this.product_size = Math.min(8, this.category_size);
}
}
</script>

The template section

Follow the steps below:

  1. We’ll display the image at the top.
  2. We’ll show the six categories in the middle.
C++
<div v-for="index in this.category_size" :key="index" class="col-md-6 col-xl-4 col-12 pt-3 justify-content-around d-flex">
<CategoryBox :category="categories[index-1]">
</CategoryBox>
</div>
  1. We’ll display a maximum of 8 products.
C++
<div v-for="index in this.product_size" :key="index" class="col-md-6 col-xl-4 col-12 pt-3 justify-content-around d-flex">
<ProductBox :product="products[index-1]">
</ProductBox>
</div>

Below is the complete code of Home.vue with some styles:

C++
<template>
<div id="home">
<!-- Page Wrapper -->
<div id="background-div" class="page-holder bg-cover">
<!-- Home image as background of #background-div-->
<div class="container py-5">
<header class="text-left text-white py-5">
<h3 class="mb-4 rounded"><a href="#start-shopping" class="bg-white px-2 py-2 rounded" id="heading">Start Shopping</a></h3>
<p id="content" class="lead mb-0 bg-dark p-1 rounded">Simple Coding Market is for educational purposes only.
It can be used by developers to learn about developing an ecommerce application complete with backend and frontend for Web and Android</p>
</header>
</div>
</div>
<!-- Categories-->
<div id="start-shopping" class="container">
<div class="row">
<div class="col-12 text-left">
<h2 class="pt-3">Top Categories</h2>
</div>
</div>
<div class="row">
<div v-for="index in this.category_size" :key="index" class="col-md-6 col-xl-4 col-12 pt-3 justify-content-around d-flex">
<CategoryBox :category="categories[index-1]">
</CategoryBox>
</div>
</div>
</div>
<hr>
<!-- Products-->
<div class="container">
<div class="row">
<div class="col-12 text-left">
<h2 class="pt-3">Top Products</h2>
</div>
</div>
<div class="row">
<div v-for="index in this.product_size" :key="index" class="col-md-6 col-xl-4 col-12 pt-3 justify-content-around d-flex">
<ProductBox :product="products[index-1]">
</ProductBox>
</div>
</div>
</div>
</div>
</template>
<script>
import ProductBox from "../components/Product/ProductBox";
import CategoryBox from "../components/Category/CategoryBox";
export default {
name: 'Home',
components : { ProductBox, CategoryBox},
props : ["baseURL", "products", "categories"],
data(){
return{
category_size:0,
product_size:0
}
},
mounted(){
this.category_size = this.categories.length;
this.category_size = Math.min(6, this.category_size);
this.product_size = this.products.length;
this.product_size = Math.min(8, this.category_size);
}
}
</script>
<style>
.page-holder {
min-height: 100vh;
}
.bg-cover {
background-size: cover !important;
}
#background-div {
background: url(../assets/home.jpg)
}
#heading {
text-decoration: none;
font-family: 'Roboto', sans-serif;
font-weight: 400;
opacity: 0.8;
font-family: 'Josefin Sans', sans-serif;
}
#content {
opacity: 0.8;
}
h2 {
font-family: 'Josefin Sans', sans-serif;
}
</style>

Below is what the category section will look like.

Below is what the product section will look like.

The final code

   ¨( @ ƒ¸Aƒ¸Aƒ¸Aƒ¸Aƒ¸Aƒ¸Aƒ¸A3ƒ¸A3ƒ¸Aƒ¸Aƒ¸Aƒ¸Aƒ¸A±ƒ¸A±ƒ¸Aƒ¸Aƒ¸Aƒ¸Aƒ¸AZƒ¸A÷ƒ¸A÷ƒ¸AZƒ¸Aƒ¸Aƒ¸Aƒ¸Aƒ¸AɃ¸Aÿƒ¸Aÿƒ¸AɃ¸Aƒ¸Aƒ¸Aƒ¸Aƒ¸Azƒ¸Aþƒ¸Aÿƒ¸Aÿƒ¸Aþƒ¸Azƒ¸Aƒ¸Aƒ¸Aƒ¸Aƒ¸A.ƒ¸A߃¸Aÿƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸A߃¸A.ƒ¸Aƒ¸Aƒ¸Aƒ¸Aƒ¸Ašƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸Ašƒ¸Aƒ¸Aƒ¸Aƒ¸Aƒ¸AHƒ¸Aðƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸Aðƒ¸AHƒ¸Aƒ¸Aƒ¸Aƒ¸Aƒ¸A¸ƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸A¸ƒ¸Aƒ¸Aƒ¸Aƒ¸Aƒ¸Afƒ¸Aúƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸Aúƒ¸Afƒ¸Aƒ¸Aƒ¸Aƒ¸A ƒ¸A҃¸Aÿƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¹Aÿƒ¹Aÿƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸A҃¸A ƒ¸Aƒ¸Aƒ¸Aƒ¸A†ƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¹Aÿ|¤?ÿ|¤?ÿƒ¹Aÿƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸A†ƒ¸Aƒ¸Aƒ¸Aƒ¸Aƒ¸A7ƒ¸A惸Aÿƒ¸Aÿƒ¸Aÿƒ¸Aÿ‚´Aÿjl9ÿjl9ÿ‚´Aÿƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸A惸A7ƒ¸Aƒ¸Aƒ¸Aƒ¸A	ƒ¸A¦ƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¹Aÿw“=ÿ_L5ÿ_L5ÿw“=ÿƒ¹Aÿƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸A¦ƒ¸A	ƒ¸Aƒ¸Aƒ¸Aƒ¸ARƒ¸Aôƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¹Aÿ€®@ÿfa8ÿ^H5ÿ^H5ÿfa8ÿ€®@ÿƒ¹Aÿƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸Aôƒ¸ARƒ¸Aƒ¸Aƒ¸Aƒ¸Aƒ¸Aƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¹Aÿr…<ÿ^I5ÿ^I5ÿ^I5ÿ^I5ÿr…<ÿƒ¹Aÿƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸Aƒ¸Aƒ¸Aƒ¸Aƒ¸Aƒ¸Aqƒ¸Aüƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¹Aÿ}¦?ÿcW7ÿ^H5ÿ^I5ÿ^I5ÿ^H5ÿcW7ÿ}¦?ÿƒ¹Aÿƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸Aüƒ¸Aqƒ¸Aƒ¸Aƒ¸Aƒ¸A(ƒ¸Aڃ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ·Aÿmv:ÿ^H5ÿ^I5ÿ^I5ÿ^I5ÿ^I5ÿ^H5ÿmv:ÿƒ·Aÿƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸Aڃ¸A(ƒ¸Aƒ¸Aƒ¸Aƒ¸A’ƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¹Aÿy›>ÿ`P6ÿ^H5ÿ^I5ÿ^I5ÿ^I5ÿ^I5ÿ^H5ÿ`P6ÿy›>ÿƒ¹Aÿƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸A’ƒ¸Aƒ¸Aƒ¸Aƒ¸Aƒ¸A@ƒ¸A샸Aÿƒ¸Aÿƒ¸Aÿƒ¸Aÿ²@ÿii9ÿ]G5ÿ^I5ÿ^I5ÿ^I5ÿ^I5ÿ^I5ÿ^I5ÿ]G5ÿii9ÿ²@ÿƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸A샸A@ƒ¸Aƒ¸Aƒ¸Aƒ¸A
ƒ¸A±ƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¹AÿuŽ=ÿ_K5ÿ^I5ÿ^I5ÿ^I5ÿ^I5ÿ^I5ÿ^I5ÿ^I5ÿ^I5ÿ_K5ÿuŽ=ÿƒ¹Aÿƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸A±ƒ¸A
ƒ¸Aƒ¸Aƒ¸Aƒ¸A]ƒ¸Aøƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¹Aÿ¬@ÿe]7ÿ^H5ÿ^I5ÿ^I5ÿ^I5ÿ^J5å^J5å^I5ÿ^I5ÿ^I5ÿ^H5ÿe]7ÿ¬@ÿƒ¹Aÿƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸Aøƒ¸A]ƒ¸Aƒ¸Aƒ¸Aƒ¸Aƒ¸Ã¸Aÿƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸Aÿp;ÿ^I5ÿ^I5ÿ^I5ÿ^I5ÿ^I5ü_L5n_L5n^I5ü^I5ÿ^I5ÿ^I5ÿ^I5ÿp;ÿƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸Ã¸Aƒ¸Aƒ¸Aƒ¸Aƒ¸A}ƒ¸Aþƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¹Aÿ|¢?ÿbT6ÿ^H5ÿ^I5ÿ^I5ÿ^I5ÿ_J5ÁaP6aP6_J5Á^I5ÿ^I5ÿ^I5ÿ^H5ÿbT6ÿ|¢?ÿƒ¹Aÿƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸Aþƒ¸A}ƒ¸Aƒ¸Aƒ¸Aƒ¸A/ƒ¸AჸAÿƒ¸Aÿƒ¸Aÿƒ¸Aÿ‚µAÿlq9ÿ^H5ÿ^I5ÿ^I5ÿ^I5ÿ^I5ó_L5P^H5^H5_L5P^I5ó^I5ÿ^I5ÿ^I5ÿ^H5ÿlq9ÿ‚µAÿƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸AჸA/ƒ¸Aƒ¸Aƒ¸Aœƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸Aÿ„ºAÿx–=ÿ`N6ÿ^I5ÿ^I5ÿ^I5ÿ^I5ÿ_K5¤bT7aQ6aQ6bT7_K5¤^I5ÿ^I5ÿ^I5ÿ^I5ÿ`N6ÿx–=ÿ„ºAÿƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸Aœƒ¸Aƒ¸AWƒ¸Aðƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¹Aÿ€¯@ÿgd8ÿ^H5ÿ^I5ÿ^I5ÿ^I5ÿ^J5å`M65_K5jf9jf9_K5`M65^J5å^I5ÿ^I5ÿ^I5ÿ^H5ÿgd8ÿ€¯@ÿƒ¹Aÿƒ¸Aÿƒ¸Aÿƒ¸Aÿƒ¸Aðƒ¸AWƒ¸Ašƒ¸Aȃ¸Aƃ¸Aƃ¸AƄºAÆv‘=Æ_K5Æ^I5Æ^I5Æ^I5Æ^I5É_K5uha9bS7bS7ha9_K5u^I5É^I5Æ^I5Æ^I5Æ_K5Æv‘=ƄºAƃ¸Aƃ¸Aƃ¸Aƃ¸Aȃ¸Ašƒ¸Aƒ¸A
ƒ¸A
ƒ¸A
ƒ¸A
ƒ¹A
lr:
\D4
^I5
^I5
^I5
^I5
`M6^H5^H5`M6^I5
^I5
^I5
^I5
\D4
lr9
ƒ¹A
ƒ¸A
ƒ¸A
ƒ¸A
ƒ¸A
ƒ¸Aÿÿÿÿÿÿÿÿÿþÿÿü?ÿÿü?ÿÿøÿÿøÿÿðÿÿàÿÿàÿÿÀÿÿÀÿÿ€ÿÿÿÿÿþþü?ü?øððààÀÀ€€€ÀÀàÿÿÿÿ
Final code