G
G
GrampyBoy2021-08-25 14:18:47
Vue.js
GrampyBoy, 2021-08-25 14:18:47

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)
      }
    })
  }
}


I tried this way, when reloading the redirect to page 10 by default I tried this way:
AJAXGETPOST( {commit}, page = 10) {

AJAXGETPOST( {commit}, page = {query: {page: page}}) {


But it gives me ?page=[object+Object]

Thanks in advance, or throw me something to read)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
GrampyBoy, 2021-08-26
@GrampyBoy

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
}

in mounted:
mounted() {
        this.AJAXGETPOST(this.page);
    },

A
Alex_mos, 2021-08-25
@Alex_mos

Maybe it's better to store it in cookies

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question