Build a Shopping Cart Using Vue js 3 Composition API Laravel 11 & Stripe Payment Gateway Part 3

3 months ago admin Vuejs

In the third part of this tutorial, we will move to the front end, we will install the packages we need, and will create the components and routes.


Install the package

All the packages we will need are below you can add them to your 'package.json' file and run npm install.

                                                        
                                                                                                                        
{
  "name": "frontend",
  "private": true,
  "version": "0.0.0",
  "type": "module",
  "scripts": {
    "dev": "vite",
    "build": "vite build",
    "preview": "vite preview"
  },
  "dependencies": {
    "@stripe/stripe-js": "^3.4.0",
    "@vue-stripe/vue-stripe": "^4.5.0",
    "axios": "^1.6.8",
    "bootstrap": "^5.3.3",
    "bootstrap-icons": "^1.11.3",
    "pinia": "^2.1.7",
    "vue": "^3.4.21",
    "vue-router": "^4.3.2",
    "vue-toastification": "^2.0.0-rc.5"
  },
  "devDependencies": {
    "@vitejs/plugin-vue": "^5.0.4",
    "vite": "^5.2.0"
  }
}


Add routes

Next, inside src add a new folder router inside add a new file 'index.js' that will hold all the routes we need.

the image below contains the file structure of the front end:

Demo

                                                            
                                                                                                                                
import { createRouter, createWebHashHistory } from "vue-router"
import Home from "../components/Home.vue"
import Cart from "../components/cart/Cart.vue"
import PaymentSuccess from "../components/payments/PaymentSuccess.vue"

const router = createRouter({
    history: createWebHashHistory(),
    routes: [
        {
            path: "/",
            name: "home",
            component: Home,
        },
        {
            path: "/cart",
            name: "cart",
            component: Cart,
        },
        {
            path: "/payment/success",
            name: "success",
            component: PaymentSuccess
        },
    ],
})

export default router


Update the file main.js

Inside the file main.js let's add the code below:

                                                            
                                                                                                                                
import { createApp } from 'vue'
import 'bootstrap/dist/css/bootstrap.min.css'
import 'bootstrap/dist/js/bootstrap.min.js'
import 'bootstrap-icons/font/bootstrap-icons.min.css'
import "vue-toastification/dist/index.css"
import './style.css'
import App from './App.vue'
import router from './router'
import { createPinia } from 'pinia'
import Toast from "vue-toastification";

const pinia = createPinia()

createApp(App)
    .use(router)
    .use(pinia)
    .use(Toast)
    .mount('#app')


Update the file App.vue

Inside the file App.vue let's add the code below:

                                                            
                                                                                                                                
<template>
    <div class="container">
      <Header></Header>
      <router-view></router-view>
    </div>
</template>

<script setup>
  import Header from './components/layouts/Header.vue'
</script>

<style scoped>
</style>


Add the header component

Inside the Header Component, we have the navigation menu.

                                                            
                                                                                                                                
<template>
    <nav class="navbar navbar-expand-lg navbar-light bg-white rounded-0 shadow-sm">
        <div class="container-fluid">
            <router-link class="navbar-brand" to="/">
                <i class="bi bi-cart h1"></i>
            </router-link>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarSupportedContent">
                <ul class="navbar-nav mb-2 mb-lg-0 mx-auto">
                    <li class="nav-item">
                        <router-link class="nav-link active" aria-current="page" to="/">
                        <i class="bi bi-house-door-fill"></i> Home </router-link>
                    </li>
                    <li class="nav-item">
                        <router-link class="nav-link" to="/cart"><i class="bi bi-cart-check"></i> ({{store.countCartItems}})</router-link>
                    </li>
                </ul>
            </div>
        </div>
    </nav>
</template>

<script setup>
    import { useCartStore } from '../../store/useCartStore.js'
    //get store
    const store = useCartStore()
</script>

<style>
</style>

Popular Tutorials

Related Tutorials

Review App Using Laravel 11 & Vue js 3 Composition API Part 5

In the last part of this tutorial, we will display the reviews list of each product, add the ability...


Review App Using Laravel 11 & Vue js 3 Composition API Part 4

In the fourth part of this tutorial, we will fetch and display all the products on the home page, vi...


Review App Using Laravel 11 & Vue js 3 Composition API Part 3

In the third part of this tutorial, we will start coding the front end, first, we will install the p...


Review App Using Laravel 11 & Vue js 3 Composition API Part 2

In the second part of this tutorial, we will create the product and review controllers, and later we...


Review App Using Laravel 11 & Vue js 3 Composition API Part 1

In this tutorial, we will create a review app using Laravel 11 & Vue js 3 Composition API, the user...


Build a Shopping Cart Using Vue js 3 Composition API Laravel 11 & Stripe Payment Gateway Part 5

In the final part of this tutorial, we will display the cart items, add the ability to increment/dec...


Build a Shopping Cart Using Vue js 3 Composition API Laravel 11 & Stripe Payment Gateway Part 4

In the fourth part of this tutorial, we will fetch and display all the products, and add the store w...


Build a Shopping Cart Using Vue js 3 Composition API Laravel 11 & Stripe Payment Gateway Part 2

In the second part of this tutorial, we will create the product and order controllers, add the...


Build a Shopping Cart Using Vue js 3 Composition API Laravel 11 & Stripe Payment Gateway Part 1

In this tutorial, we will create a shopping cart using vue js 3 composition API Laravel 11 and strip...


How to Get URL Query Params in Vue 3 Composition API

In this lesson, we will see how to get URL query params in Vue 3 composition API, let's assume that...