Skip to content

Instantly share code, notes, and snippets.

@jaouadballat
Created March 3, 2018 17:29
Show Gist options
  • Save jaouadballat/ce9c77c8243532b2321f31d5ab8c0881 to your computer and use it in GitHub Desktop.
Save jaouadballat/ce9c77c8243532b2321f31d5ab8c0881 to your computer and use it in GitHub Desktop.
<template>
<nav class="navbar navbar-expand-lg navbar-light bg-light mb-3">
<div class="container">
<router-link tag="a" :to = "{name: 'home'}" class="navbar-brand">Shopping Cart</router-link>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ml-auto">
<li class="nav-item active" v-for="category in categories" :key="category._id">
<router-link tag="a" :to = "{name: 'category', params: {category: category.title}}" class="nav-link">{{ category.title }}</router-link>
</li>
<router-link tag="a" :to = "{name: 'checkout'}" class="nav-link">Cart(<span class="badge badge-light">{{ cart.length }}</span>)</router-link>
</ul>
</div>
</div>
</nav>
</template>
<script>
import Api from '@/config/Api'
export default {
data() {
return {
categories: []
}
},
created() {
Api().get('/categories')
.then(response => {
this.categories = response.data;
});
},
computed: {
cart() {
return this.$store.getters.getCart
}
}
}
</script>
<style>
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment