a298003154 626ca4954c
fix(List): remove unused Less var @list-icon-margin-right (#8758)
* docs(PullRefresh): fix spell check

* style(cli): fix spell check about "toogle" -> "toggle" in DemoPlayground.vue

* style(Button): fix spell error

* feat(List): remove unused Less var @list-icon-margin-right
2021-05-25 11:17:15 +08:00
..
2020-03-21 14:46:02 +08:00

List

Intro

A list component to show items and control loading status.

Install

import Vue from 'vue';
import { List } from 'vant';

Vue.use(List);

Usage

Basic Usage

<van-list
  v-model="loading"
  :finished="finished"
  finished-text="Finished"
  @load="onLoad"
>
  <van-cell v-for="item in list" :key="item" :title="item" />
</van-list>
export default {
  data() {
    return {
      list: [],
      loading: false,
      finished: false,
    };
  },
  methods: {
    onLoad() {
      setTimeout(() => {
        for (let i = 0; i < 10; i++) {
          this.list.push(this.list.length + 1);
        }
        this.loading = false;

        if (this.list.length >= 40) {
          this.finished = true;
        }
      }, 1000);
    },
  },
};

Error Info

<van-list
  v-model="loading"
  :error.sync="error"
  error-text="Request failed. Click to reload"
  @load="onLoad"
>
  <van-cell v-for="item in list" :key="item" :title="item" />
</van-list>
export default {
  data() {
    return {
      list: [],
      error: false,
      loading: false,
    };
  },
  methods: {
    onLoad() {
      fetchSomeThing().catch(() => {
        this.error = true;
      });
    },
  },
};

PullRefresh

<van-pull-refresh v-model="refreshing" @refresh="onRefresh">
  <van-list
    v-model="loading"
    :finished="finished"
    finished-text="Finished"
    @load="onLoad"
  >
    <van-cell v-for="item in list" :key="item" :title="item" />
  </van-list>
</van-pull-refresh>
export default {
  data() {
    return {
      list: [],
      loading: false,
      finished: false,
      refreshing: false,
    };
  },
  methods: {
    onLoad() {
      setTimeout(() => {
        if (this.refreshing) {
          this.list = [];
          this.refreshing = false;
        }

        for (let i = 0; i < 10; i++) {
          this.list.push(this.list.length + 1);
        }
        this.loading = false;

        if (this.list.length >= 40) {
          this.finished = true;
        }
      }, 1000);
    },
    onRefresh() {
      this.finished = false;
      this.loading = true;
      this.onLoad();
    },
  },
};

API

Props

Attribute Description Type Default
v-model Whether to show loading infothe load event will not be Emitted when loading boolean false
finished Whether loading is finishedthe load event will not be Emitted when finished boolean false
error Whether loading is errorthe load event will be Emitted only when error text clicked, the sync modifier is needed boolean false
offset The load event will be Emitted when the distance between the scrollbar and the bottom is less than offset number | string 300
loading-text Loading text string Loading...
finished-text Finished text string -
error-text Error loaded text string -
immediate-check Whether to check loading position immediately after mounted boolean true
direction Scroll directioncan be set to up string down

Events

Event Description Arguments
load Emitted when the distance between the scrollbar and the bottom is less than offset -

Methods

Use ref to get List instance and call instance methods.

Name Description Attribute Return value
check Check scroll position - -

Slots

Name Description
default List content
loading Custom loading tips
finished Custom finished tips
error Custom error tips

Less Variables

How to use: Custom Theme.

Name Default Value Description
@list-text-color @gray-6 -
@list-text-font-size @font-size-md -
@list-text-line-height 50px -