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>
<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, а пушишь в роутер?