Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: content和totalPages的某些组合会导致无限loading #81

Merged
merged 3 commits into from
Oct 21, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/data-list.vue
Original file line number Diff line number Diff line change
Expand Up @@ -203,18 +203,27 @@ export default {
const action = isDirectionDown ? 'push' : 'unshift'
this.list[action](...data)

if (!!this.list.length) $state.loaded()
if (this.list.length === 0) return $state.complete()
$state.loaded()
/**
* 请求完loaded事件
* @property {array} list - 列表数据
* @property {object} resp - 接口返回的数据
*/
this.$emit('loaded', [...this.list], resp)

const totalPages = _get(resp, this.totalPagesPath, 0)
/**
* data-list约定后端返回的页码范围是 defaultFirstPage ~ totalPages
* 如果没有 totalPages 或 page 越界但仍有数据(nextPage > totalPages || prevPage < defaultFirstPage)
* data-list只能立即complete
*/
const totalPages = _get(resp, this.totalPagesPath, null)
if (totalPages === null)
console.warn('totalPages 字段不存在,请传入正确的 totalPagesPath')
if (
(isDirectionDown && this.nextPage === totalPages) ||
(!isDirectionDown && this.prevPage === defaultFirstPage)
totalPages === null ||
(isDirectionDown && this.nextPage >= totalPages) ||
(!isDirectionDown && this.prevPage <= defaultFirstPage)
) {
$state.complete()
/**
Expand Down