Hi all, I got a problem when building SPA with vuejs using vue-router.
Everything works great without pagination.
But when i go to next page.
It is not update new Route
Somebody helps me out, please!
Here is my code:
<template>
<div class="category-view">
<topic
v-for="topic in topics"
:topic="topic">
</topic>
<div class="Pagination">
<router-link
v-if="page > 1"
:to="{ name: 'category', params: { categoryId: categoryId}, query:{page : page + 1}}"
class="Page-link Page-link--prev" replace>
Back
</router-link>
<router-link
v-if="page < lastPage"
:to="{ name: 'category', params: { categoryId: categoryId}, query:{page : page + 1}}"
class="Page-link Page-link--next" replace>
Next
</router-link>
</div>
</div>
</template>
<script>
import Topic from './Topic.vue';
export default {
components: { Topic },
data () {
return {
topics: [],
categoryId: 0,
page: 1,
lastPage: 1
}
},
created(){
this.fetchTopics();
},
methods:{
fetchTopics(){
this.categoryId = this.$route.params.categoryId;
this.page = this.$route.query.page || 1;
axios.get('/api/categories/'+ this.categoryId +'/topics')
.then(response => {
this.topics = response.data.data;
this.lastPage = response.data.last_page;
})
.catch(error => {
console.log("Error..." + error.response)
});
}
}
}
</script>