Skip to content

Waterfall 瀑布流组件

瀑布流组件

Waterfall 组件位于 src/components/Waterfall

TIP

data 数据必须带有高度字段,用于确保计算出正确的位置

用法

vue
<script lang="ts" setup>
import { Waterfall } from '@/components/Waterfall'
import Mock from 'mockjs'
import { ref, unref } from 'vue'
import { toAnyString } from '@/utils'

const data = ref<any>([])

const getList = () => {
  const list: any = []
  for (let i = 0; i < 20; i++) {
    // 随机 100, 500 之间的整数
    const height = Mock.Random.integer(100, 500)
    const width = Mock.Random.integer(100, 500)
    list.push(
      Mock.mock({
        width,
        height,
        id: toAnyString(),
        image_uri: Mock.Random.image(`${width}x${height}`)
      })
    )
  }
  data.value = [...unref(data), ...list]
  if (unref(data).length >= 60) {
    end.value = true
  }
}
getList()

const loading = ref(false)

const end = ref(false)

const loadMore = () => {
  loading.value = true
  setTimeout(() => {
    getList()
    loading.value = false
  }, 1000)
}
</script>

<template>
  <Waterfall
    :data="data"
    :loading="loading"
    :end="end"
    :props="{
      src: 'image_uri',
      height: 'height'
    }"
    @load-more="loadMore"
  />
</template>

Waterfall 属性

属性说明类型可选值默认值
data要展示的数据Array--
reset窗口变化是否重新布局booleantrue/falsetrue
width每个项的宽度number-200
gap每个项的间距number-20
loadingText加载中文字string-加载中...
loading是否加载中boolean-false
end是否加载结束boolean-false
endText是否加载结束文字string-没有更多了
props字段别名object-{ src: 'src', height: 'height' }

Waterfall 事件

方法名说明回调参数
loadMore加载更多事件-