
<template>
    <van-list
        ref="list"
        v-model="loading"
        :finished="finished"
        finished-text="没有更多了"
        loading-text="加载中..."
        :error.sync="loadError"
        :error-text="loadErrorText"
        @load="handleLoad">
        <slot></slot>
    </van-list>
</template>

<script>
    import { List as VanList } from 'vant'
    export default {
        name: 'AsScrollLoading',
        data () {
            return {
                loading: false,
                loadError: false,
                loadErrorText: '',
            }
        },
        props: {
            finished: { type: Boolean, default: false },
        },
        methods: {
            handleLoad () {
                this.$emit('load', err => {
                    this.loadError = !!err;
                    this.loadErrorText = err ? `${err}，点击重新加载` : '';
                    this.loading = false;
                });
            },
            resetError () {
                this.loadError = false;
                this.loadErrorText = '';
            },
            check () {
                this.$refs.list.check();
            },
        },
        components: {
            VanList,
        }
    }
</script>
