Why not fire the call $router.push( )?

0 like 0 dislike
228 views
Hello friends!
Now studying Vue.js and to consolidate writing a test application with a RESTful backend.
Created a component to display the records with the possibility of pagination
<!--Блок с контентом-->{{customer.id}} fas fa-phone{{customer.phone}} <!--Блок пагинации-->{{i}} import axios from 'axios';export default {name: 'Customer',data() {return {customers: [],curPage: 0,pageCount: 0,}},created() {this.loadCustomers();},methods: {loadCustomers() {let fullPath = this.$route.fullPath;axios.get('http://rest.loc' + fullPath).then(response => {this.customers = response.data;let headers = response.headers;this.curPage = headers['x-pagination-current-page'];this.pageCount = headers['x-pagination-page-count'];}).catch(e => {console.log(e);})},paginate(number) {this.$router.push('/customers?page=' + number);//Как сделать чтобы работало без следующей строчкиthis.loadCustomers();}}}


1. Pagination only works if you call loadCustomers().
2. When you press forward or back in the browser at the address bar changes, but the data on the page - no
What am I missing?

I'll give you another router.js
import Vue from 'vue' import Router from 'vue-router' Home import from './components/Home.vue' About import from './components/About.vue' Customer import from './components/Customer Vue.use(Router) export default new Router({ mode: 'history', routes: [ { path: '/', name: 'Home', component: Home }, { path: '/about', name: 'about', component: About }, { path: '/customers', name: 'customers', component: Customer } ] })
by | 228 views

2 Answers

0 like 0 dislike
watch: { '$route.query.page'() { this.loadCustomers(); } },
by
0 like 0 dislike
Maybe so?:
.push({path:'/customers?page=' + number});
by

Related questions

0 like 0 dislike
2 answers
asked Aug 12, 2019 by serega_chem
0 like 0 dislike
2 answers
asked Jul 3, 2019 by serega_chem
0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
110,608 questions
257,187 answers
0 comments
40,796 users