/** * Create with WebStorm * Author: Daxiu Huang * CreateTime: 2017/9/6 10:21 */ //分页组件 var pageComponent = Vue.extend({ template: '', props: { pages: { type: Number, default: 1 }, current: { type: Number, default: 1 }, total: { type: Number, default: false }, size: { type: Number, default: false } }, data: function(){ return{ curPage:1 } }, computed: { showPageBtn: function() { var pageNum = this.pages; var index = this.curPage; var arr = []; if (pageNum <= 5) { for (var i = 1; i <= pageNum; i++) { arr.push(i) } return arr } if (index <= 2) return [1, 2, 3, 0, pageNum]; if (index >= pageNum - 1) return [1, 0, pageNum - 2, pageNum - 1, pageNum]; if (index === 3) return [1, 2, 3, 4, 0, pageNum]; if (index === pageNum - 2) return [1, 0, pageNum - 3, pageNum - 2, pageNum - 1, pageNum]; return [1, 0, index - 1, index, index + 1, 0, pageNum]; } }, methods: { goPage: function(page) { if (page != this.curPage) { console.log(page); this.curPage = page; this.$emit('navpage', this.curPage); }else{ console.log('Already in the current page'); } } } }); Vue.component('navigation', pageComponent);