Vant

一款由有赞出品的适用于移动端电商业务的vue组件库

Posted by page on July 30, 2021

Vant

官方文档

弹窗popup

飘入动画

  • 传入 props.position 值为 top

  • van-popup 宽高100% 覆盖

常见问题

mounted 中无法获取dom:默认懒渲染, lazy-render 参数须为 false

已关闭弹窗报错:弹窗关闭并不销毁节点,为弹窗内容添加 v-if 销毁

列表list

下拉列表加载

<van-list
  v-if="showList"
  v-model="loading"
  :finished="finished"
  :immediate-check="false"
  error-text="加载失败..."
  @load="getList"
  :offset="100"
>
  <div v-for="(item, i) in list"></div>
</van-list>

<script>
  let loading = false;  // 下拉加载中
  let finished = false;  // 全部加载完成
  function getList() {
     // request handle...
     this.loading = false;
     pageIndex * pageSize >= total && (finished = true);
  }
  
  // 切换列表数据:先销毁列表节点
  let showList = true;
  let requesting = true;
  function changeList() {
    showList = false;
    this.$nextTick(() => {
      pageIndex = 1;
      finished = false;
      showList = true;
      list = [];
      requesting = false;
      await getList();
      requesting = true;
    });
  };
</script>