一个可复用的vue分页组件(2)

methods: { // 查询全部订单 getorderfromServer(){ this.loading = true; this.page = this.$route.params.page; getorderfromServer({ currentPage: this.page, orderTimeStart:this.orderTimeStart, orderTimeEnd:this.orderTimeEnd, serviceName:this.serviceName, shopName:this.shopName, status: this.status }).then(({code, data}) => { if (code == 200) { this.Orderlist = data.list; this.totalPage = data.totalPage; } this.loading = false; }).catch(err => { this.tip('服务内部错误', 'error'); this.Orderlist = {}; this.loading = false; }); }, }

注意通过路由对方法作出响应,每次路由改变都调用此方法以更新页面

watch: { $route: 'getorderfromServer' }

还要对路由信息进行改造,让每一页(尤其是第一页)都有路由页数信息,可以对第一页进行重定向以达到目的:

{ path: 'order', redirect: 'order/page/1', }, { path: 'order/page/:page', component(resolve){ require.ensure([], function (require) { resolve(require('../modules/personal/order/myorder.vue')); }, 'modules/personal') }, name:'order', meta: { login: 'none' } },

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wysfyz.html