I have my index.vue
inside the page folder and I am trying to loop all the category gotten from the api so I did this.
<template>
<div>
<Header :category="category" />
</div>
</template>
<script>
import Header from '@/components/Front/Header'
export default {
name: 'MainSite',
components: {
Header,
},
props: ['category', 'name'],
data: () => ({
frontpage: [],
category: [],
}),
async fetch() {
const response = await this.$axios.get('/api/frontpage')
this.frontpage = response.data.posts
this.category = response.data.cat
},
}
</script>
I have the Header.vue
as this which contains the navigation link I want to loop through
<template>
<div class="collapse navbar-collapse">
<!-- menus -->
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<NuxtLink class="nav-link" to="/">Home</NuxtLink>
</li>
<li v-for="(cat, i) in category" :key="i.name" class="nav-item">
<NuxtLink class="nav-link" :to="'/category/' + cat.slug">{{
cat.name
}}</NuxtLink>
</li>
<template v-if="$auth.user">
<li class="nav-item">
<a class="nav-link" href="/dashboard">Admin</a>
</li>
</template>
</ul>
</div>
</template>
<script>
export default {
name: 'Header',
props: ['category', 'name'],
}
</script>
I keep getting this error
Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the prop's value. Prop being mutated: "category"
and also this error
client.js?06a0:57 [Vue warn]: The data property "category" is already declared as a prop. Use prop default value instead.
Anytime I reload the browser the links gets displayed and the disappears with those errors above and this also
<template>
<li class="nav-item" data-v-383d0eae="">
<a href="/category/video" class="nav-link" data-v-383d0eae="">Video</a>
</li>
</template>