zx-infinite-scroll 1.0.4 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -77
- package/dist/index.es.js +204 -196
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -20,87 +20,27 @@ npm install zx-infinite-scroll
|
|
|
20
20
|
|
|
21
21
|
## 快速开始
|
|
22
22
|
|
|
23
|
-
### ⭐ 推荐:全局引入样式(最简单)
|
|
24
|
-
|
|
25
|
-
在 `main.ts` 中全局引入样式**一次**即可:
|
|
26
|
-
|
|
27
|
-
```ts
|
|
28
|
-
import { createApp } from 'vue';
|
|
29
|
-
import App from './App.vue';
|
|
30
|
-
import 'zx-infinite-scroll/dist/style.css'; // 👈 只需引入一次
|
|
31
|
-
|
|
32
|
-
const app = createApp(App);
|
|
33
|
-
app.mount('#app');
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
之后在任何组件中使用都**不需要**再引入样式:
|
|
37
|
-
|
|
38
23
|
```vue
|
|
39
24
|
<script setup>
|
|
40
25
|
import { InfiniteScrollV2 } from 'zx-infinite-scroll';
|
|
41
|
-
|
|
26
|
+
|
|
27
|
+
const fetchData = async ({ page, pageSize }) => {
|
|
28
|
+
// 你的请求逻辑
|
|
29
|
+
return { records: [], total: 0 };
|
|
30
|
+
};
|
|
42
31
|
</script>
|
|
43
32
|
|
|
44
33
|
<template>
|
|
45
34
|
<InfiniteScrollV2 :fetch-fn="fetchData">
|
|
46
|
-
|
|
35
|
+
<template #default="{ list }">
|
|
36
|
+
<div v-for="item in list" :key="item.id">
|
|
37
|
+
{{ item.name }}
|
|
38
|
+
</div>
|
|
39
|
+
</template>
|
|
47
40
|
</InfiniteScrollV2>
|
|
48
41
|
</template>
|
|
49
42
|
```
|
|
50
43
|
|
|
51
|
-
---
|
|
52
|
-
|
|
53
|
-
### 方式一:手动引入样式(每次使用都要引入)
|
|
54
|
-
|
|
55
|
-
如果不想全局引入,每次使用时手动引入:
|
|
56
|
-
|
|
57
|
-
```vue
|
|
58
|
-
<script setup>
|
|
59
|
-
import { InfiniteScrollV2 } from 'zx-infinite-scroll';
|
|
60
|
-
import 'zx-infinite-scroll/dist/style.css'; // 👈 每次都要引入
|
|
61
|
-
</script>
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
---
|
|
65
|
-
|
|
66
|
-
### 方式二:使用 unplugin-vue-components 自动导入(高级)
|
|
67
|
-
|
|
68
|
-
安装插件:
|
|
69
|
-
|
|
70
|
-
```bash
|
|
71
|
-
npm install -D unplugin-vue-components
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
配置 `vite.config.ts`:
|
|
75
|
-
|
|
76
|
-
```ts
|
|
77
|
-
import { defineConfig } from 'vite';
|
|
78
|
-
import vue from '@vitejs/plugin-vue';
|
|
79
|
-
import Components from 'unplugin-vue-components/vite';
|
|
80
|
-
|
|
81
|
-
export default defineConfig({
|
|
82
|
-
plugins: [
|
|
83
|
-
vue(),
|
|
84
|
-
Components({
|
|
85
|
-
resolvers: [
|
|
86
|
-
// 自定义解析器
|
|
87
|
-
(componentName) => {
|
|
88
|
-
if (componentName.startsWith('InfiniteScroll')) {
|
|
89
|
-
return {
|
|
90
|
-
name: componentName,
|
|
91
|
-
from: 'zx-infinite-scroll',
|
|
92
|
-
sideEffects: 'zx-infinite-scroll/dist/style.css'
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
]
|
|
97
|
-
})
|
|
98
|
-
]
|
|
99
|
-
});
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
这样组件和样式都会自动按需导入,无需手动 import!
|
|
103
|
-
|
|
104
44
|
|
|
105
45
|
|
|
106
46
|
## 使用
|
|
@@ -110,7 +50,6 @@ export default defineConfig({
|
|
|
110
50
|
```vue
|
|
111
51
|
<script setup lang="ts">
|
|
112
52
|
import { InfiniteScrollV2 } from 'zx-infinite-scroll';
|
|
113
|
-
import 'zx-infinite-scroll/dist/style.css';
|
|
114
53
|
|
|
115
54
|
interface Item {
|
|
116
55
|
id: number;
|
|
@@ -147,7 +86,6 @@ const fetchData = async ({ page, pageSize }) => {
|
|
|
147
86
|
```ts
|
|
148
87
|
import { createApp } from 'vue';
|
|
149
88
|
import InfiniteScrollPlugin from 'zx-infinite-scroll';
|
|
150
|
-
import 'zx-infinite-scroll/dist/style.css';
|
|
151
89
|
import App from './App.vue';
|
|
152
90
|
|
|
153
91
|
const app = createApp(App);
|
|
@@ -255,7 +193,6 @@ interface FetchResult<T> {
|
|
|
255
193
|
<script setup lang="ts">
|
|
256
194
|
import { ref } from 'vue';
|
|
257
195
|
import { InfiniteScroll } from 'zx-infinite-scroll';
|
|
258
|
-
import 'zx-infinite-scroll/dist/style.css';
|
|
259
196
|
|
|
260
197
|
const list = ref([]);
|
|
261
198
|
const loading = ref(false);
|
|
@@ -338,7 +275,6 @@ const onRefresh = async () => {
|
|
|
338
275
|
```vue
|
|
339
276
|
<script setup lang="ts">
|
|
340
277
|
import { InfiniteScrollV2 } from 'zx-infinite-scroll';
|
|
341
|
-
import 'zx-infinite-scroll/dist/style.css';
|
|
342
278
|
|
|
343
279
|
interface Item {
|
|
344
280
|
id: number;
|
|
@@ -372,7 +308,6 @@ const fetchData = async ({ page, pageSize }) => {
|
|
|
372
308
|
<script setup lang="ts">
|
|
373
309
|
import { ref } from 'vue';
|
|
374
310
|
import { InfiniteScrollV2 } from 'zx-infinite-scroll';
|
|
375
|
-
import 'zx-infinite-scroll/dist/style.css';
|
|
376
311
|
|
|
377
312
|
const keyword = ref('');
|
|
378
313
|
const category = ref('');
|
|
@@ -414,7 +349,6 @@ const fetchData = async ({ page, pageSize, keyword, category }) => {
|
|
|
414
349
|
```vue
|
|
415
350
|
<script setup lang="ts">
|
|
416
351
|
import { InfiniteScrollV2 } from 'zx-infinite-scroll';
|
|
417
|
-
import 'zx-infinite-scroll/dist/style.css';
|
|
418
352
|
|
|
419
353
|
const handleSuccess = ({ records, total, reset }) => {
|
|
420
354
|
console.log('加载成功', { records, total, reset });
|
|
@@ -453,7 +387,6 @@ const fetchData = async ({ page, pageSize }) => {
|
|
|
453
387
|
<script setup lang="ts">
|
|
454
388
|
import { ref } from 'vue';
|
|
455
389
|
import { InfiniteScroll } from 'zx-infinite-scroll';
|
|
456
|
-
import 'zx-infinite-scroll/dist/style.css';
|
|
457
390
|
|
|
458
391
|
const scrollRef = ref();
|
|
459
392
|
const list = ref([]);
|