Answer the question
In order to leave comments, you need to log in
Why is there nothing in my store?
https://github.com/YakovSPb/Vue_Nuxt_Copters
in the store file
export const state = () => ({
copters: []
})
export const mutations = {
setUsers(state, copters) {
state.copters = copters
}
}
export const actions = {
async fetch({commit}) {
const copters = await this.$axios.$get('https://jsonplaceholder.typicode.com/users')
commit('setUsers', copters)
}
}
export const getters = {
copters: s => s.copters
}
<script>
export default {
async fetch({store}) {
if (store.copters['copters/copters'].length === 0) {
await store.dispatch('copters/fetch')
}
},
data: () => ({
pageTitle: 'Users page'
}),
computed: {
copters() {
return this.$store.getters['copters/copters']
}
},
methods: {
openUser(user) {
this.$router.push('/copters/' + user.id)
}
}
}
</script>
Answer the question
In order to leave comments, you need to log in
This is
if (store.copters['copters/copters'].length === 0) {
if (store.getters['copters/copters'].length === 0)
Cloned the turnip.
the question arises, why do you think that in async fetch () you have a store ???
twisted it to start. it happened like this.
<script>
import {mapGetters} from 'vuex'
export default {
async fetch() {
if (this.copters.length === 0) {
await this.$store.dispatch('copters/fetch')
}
},
data: () => ({
pageTitle: 'Users page'
}),
computed: {
...mapGetters('copters', ['copters']),
},
methods: {
openUser(user) {
this.$router.push('/copters/' + user.id)
}
}
}
</script>
А почему ты не хочшь использовать nuxt-link, а пушишь в роутер?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question