In my Nuxt page I have a navigation component where I try to achieve something like
[Logo] [Product] [Infos] [Jobs(2)]
Where (2) is a flag representing the number of items in the corresponding "jobs" content folder. I tried to fill the state but couldn't get it working. My state looks like this:
export const state = () => ({
jobsLength: null,
})
export const mutations = {
setJobsLength(state, payload) {
state.jobsLength = payload.length
},
}
export const getters = {
getJobsLength(state) {
return state.jobsLength
},
}
export const actions = {
async fetch({ $content, commit }) {
const jobs = await $content('jobs').fetch()
commit('setJobsLength', jobs.length)
},
}
My Navigation.vue Component:
<a href="/jobs">
Jobs {{ getJobsLength }}
</a>
....
<script>
import { mapGetters, mapMutations, mapActions } from 'vuex'
export default {
computed: {
...mapGetters({
getJobsLength: 'jobsLength/getJobsLength',
}),
},
mounted() {
this.fetchJobs()
},
methods: {
...mapActions({
fetchJobs: 'jobsLength/fetch',
}),
},
}
</script>
The response is
Uncaught (in promise) TypeError: $content is not a function
I feel like I'm missing something but after like 2-3h in the code I'm blind.