Answer the question
In order to leave comments, you need to log in
Laravel - vue3 - vuex - pagination. How to save on reboot?
Good day, there is pagination that works, but when the page is reloaded, everything returns to the first page, and /api/posts?page=undefined arrives in the console and displays the first page (Or the page that I specify (page = 10) - everything is fine here and in response /api/posts?page=10 ). I know where the jamb is, but I don’t know how to fix it T_T
Here is the action itself
const actions = {
AJAXGETPOST( {commit}, page) { // <-- тут косяк
commit('LOADINGSTATUS', true)
axios.get('/api/posts?page=' + page)
.then(response => {
commit('GETPOSTS', response.data.result );
})
.then(response => {
commit('LOADINGSTATUS', false)
if (page > 1) {
router.push({query: {page: page}}); // Что-б url был с ?posts=...
} else {
router.push({query: {}}); // Что-б на 1 странице url был без ?posts=...
}
})
.catch((error) => {
console.log(error)
}
})
}
}
AJAXGETPOST( {commit}, page = 10) {
AJAXGETPOST( {commit}, page = {query: {page: page}}) {
Answer the question
In order to leave comments, you need to log in
You can also try cookies, but it's very interesting to figure it out. On the docks I see only through vue-router, but through vuex N_N
UPD:
Figured it out
, forgot to unsubscribe: Added to
computed
page () {
return this.$route.query.page || 1
}
mounted() {
this.AJAXGETPOST(this.page);
},
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question