Skip to content

Commit

Permalink
0.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
lhlyu committed Jul 27, 2023
1 parent e122fc4 commit 4d44cb3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,21 @@
- 局部引用

```ts
import { VirtualWaterfall } from '@lhlyu/vue-virtual-waterfall'
import {VirtualWaterfall} from '@lhlyu/vue-virtual-waterfall'
```

- 全局引用

```ts
import VueVirtualWaterfall from '@lhlyu/vue-virtual-waterfall'
import VueVirtualWaterfall from '@lhlyu/vue-virtual-waterfall'

app.use(VueVirtualWaterfall)
```

- 使用

```vue
<template>
<VirtualWaterfall :items="items" :calcItemHeight="calcItemHeight" :loading="loading" @load-more="loadMoreData">
<template #default="{ item }: { item: ItemOption }">
Expand All @@ -51,6 +52,8 @@ app.use(VueVirtualWaterfall)
| preloadScreenCount | number | 1 | 预加载屏数量 |
| bottomDistance | number | 2000 | 距离底部多少时触发加载更多事件 |
| itemMinWidth | number | 250 | 每个item最小宽度 |
| maxColumnCount | number | | 允许的最大列数,默认没有限制 |
| minColumnCount | number | 2 | 允许的最小列数 |
| loading | boolean | false | 是否正在加载数据 |
| items | any[] | [] | 数据 |
| calcItemHeight | (item: any, itemWidth: number) => number | (item: any, itemWidth: number) => 0 | 计算item高度的方法 |
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"name": "@lhlyu/vue-virtual-waterfall",
"description": "vue3 virtual waterfall component",
"version": "0.0.6",
"version": "0.0.7",
"author": "lhlyu",
"repository": {
"type": "git",
"url": "https://github.com/lhlyu/vue-virtual-waterfall.git"
},
"license": "MIT",
"type": "module",
"scripts": {
"fmt": "prettier --write .",
Expand Down
2 changes: 1 addition & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<main>
<VirtualWaterfall :items="data.items" :calcItemHeight="calcItemHeight" :loading="data.loading" contentMaxWidth="1000px" ref="vw" @load-more="loadMoreData">
<VirtualWaterfall :items="data.items" :calcItemHeight="calcItemHeight" :loading="data.loading" :content-max-width="1000" ref="vw" @load-more="loadMoreData">
<template #default="{ item }: { item: ItemOption }">
<Card :id="item.id" :img="item.img" :color="item.dominant" :has="loadedItemIds.has(item.id)" @loaded="loaded"></Card>
</template>
Expand Down
13 changes: 11 additions & 2 deletions src/vue-virtual-waterfall/virtual-waterfall.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ interface VirtualWaterfallOption {
contentMaxWidth?: string | number
// item最小宽度
itemMinWidth?: number
// 最大列数
maxColumnCount?: number
// 最小列数
minColumnCount?: number
// 是否正在加载数据
loading?: boolean
// 数据
Expand All @@ -61,6 +65,7 @@ const props = withDefaults(defineProps<VirtualWaterfallOption>(), {
bottomDistance: 2000,
contentMaxWidth: '100%',
itemMinWidth: 250,
minColumnCount: 2,
loading: false,
items: () => [],
calcItemHeight: (item: any, itemWidth: number) => 0
Expand Down Expand Up @@ -109,9 +114,13 @@ const columnCount = computed<number>(() => {
}
const cWidth = contentWidth.value + props.gap * 2
if (cWidth >= props.itemMinWidth * 2) {
return Math.ceil(cWidth / props.itemMinWidth)
const count = Math.ceil(cWidth / props.itemMinWidth)
if (props.maxColumnCount && count > props.maxColumnCount) {
return props.maxColumnCount
}
return count
}
return 2
return props.minColumnCount
})
// 每列距离顶部的距离
Expand Down

0 comments on commit 4d44cb3

Please sign in to comment.