| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- export default {
- data() {
- return {
- empty: false,
- loading: false,
- finished: false,
- page: 0,
- totalElements: 0,
- size: 20
- };
- },
- methods: {
- getData(isFirst = false, scrollTop = 0) {
- if (isFirst) {
- this.page = 0;
- this.list = [];
- this.$root.$el.scrollTop = scrollTop;
- }
- this.loading = true;
- this.finished = false;
- this.empty = false;
- let data = { page: this.page, size: this.size, sort: 'createdAt,desc' };
- if (this.beforeData) {
- data = {
- ...data,
- ...this.beforeData()
- };
- }
- if (this.httpType === 'get') {
- return this.$http.get(this.url, data, { body: 'json' }).then(res => {
- if (res.first) {
- this.list = [];
- }
- this.list = [...this.list, ...res.content];
- this.empty = res.empty;
- this.loading = false;
- this.finished = res.last;
- if (!this.finished) {
- this.page = this.page + 1;
- }
- this.totalElements = Number(res.totalElements);
- });
- } else {
- return this.$http.post(this.url, data, { body: 'json' }).then(res => {
- if (res.first) {
- this.list = [];
- }
- this.list = [...this.list, ...res.content];
- this.empty = res.empty;
- this.loading = false;
- this.finished = res.last;
- if (!this.finished) {
- this.page = this.page + 1;
- }
- this.totalElements = Number(res.totalElements);
- });
- }
- }
- }
- };
|