zx-infinite-scroll 1.0.3 → 1.0.6
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 +15 -75
- 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 +9 -1
package/README.md
CHANGED
|
@@ -20,97 +20,43 @@ npm install zx-infinite-scroll
|
|
|
20
20
|
|
|
21
21
|
## 快速开始
|
|
22
22
|
|
|
23
|
-
###
|
|
23
|
+
### ✨ 样式自动注入
|
|
24
24
|
|
|
25
|
-
|
|
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
|
-
之后在任何组件中使用都**不需要**再引入样式:
|
|
25
|
+
**无需手动引入样式!** 只要导入组件,样式会自动注入到页面中。
|
|
37
26
|
|
|
38
27
|
```vue
|
|
39
28
|
<script setup>
|
|
40
29
|
import { InfiniteScrollV2 } from 'zx-infinite-scroll';
|
|
41
|
-
// ✅
|
|
30
|
+
// ✅ 样式已自动注入,无需手动 import 'xxx/style.css'
|
|
31
|
+
|
|
32
|
+
const fetchData = async ({ page, pageSize }) => {
|
|
33
|
+
// 你的请求逻辑
|
|
34
|
+
return { records: [], total: 0 };
|
|
35
|
+
};
|
|
42
36
|
</script>
|
|
43
37
|
|
|
44
38
|
<template>
|
|
45
39
|
<InfiniteScrollV2 :fetch-fn="fetchData">
|
|
46
|
-
|
|
40
|
+
<template #default="{ list }">
|
|
41
|
+
<div v-for="item in list" :key="item.id">
|
|
42
|
+
{{ item.name }}
|
|
43
|
+
</div>
|
|
44
|
+
</template>
|
|
47
45
|
</InfiniteScrollV2>
|
|
48
46
|
</template>
|
|
49
47
|
```
|
|
50
48
|
|
|
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
49
|
|
|
105
50
|
|
|
106
51
|
## 使用
|
|
107
52
|
|
|
53
|
+
> 💡 **提示**:样式已自动注入,无需手动引入 CSS 文件!
|
|
54
|
+
|
|
108
55
|
### 方式一:按需引入
|
|
109
56
|
|
|
110
57
|
```vue
|
|
111
58
|
<script setup lang="ts">
|
|
112
59
|
import { InfiniteScrollV2 } from 'zx-infinite-scroll';
|
|
113
|
-
import 'zx-infinite-scroll/dist/style.css';
|
|
114
60
|
|
|
115
61
|
interface Item {
|
|
116
62
|
id: number;
|
|
@@ -147,7 +93,6 @@ const fetchData = async ({ page, pageSize }) => {
|
|
|
147
93
|
```ts
|
|
148
94
|
import { createApp } from 'vue';
|
|
149
95
|
import InfiniteScrollPlugin from 'zx-infinite-scroll';
|
|
150
|
-
import 'zx-infinite-scroll/dist/style.css';
|
|
151
96
|
import App from './App.vue';
|
|
152
97
|
|
|
153
98
|
const app = createApp(App);
|
|
@@ -255,7 +200,6 @@ interface FetchResult<T> {
|
|
|
255
200
|
<script setup lang="ts">
|
|
256
201
|
import { ref } from 'vue';
|
|
257
202
|
import { InfiniteScroll } from 'zx-infinite-scroll';
|
|
258
|
-
import 'zx-infinite-scroll/dist/style.css';
|
|
259
203
|
|
|
260
204
|
const list = ref([]);
|
|
261
205
|
const loading = ref(false);
|
|
@@ -338,7 +282,6 @@ const onRefresh = async () => {
|
|
|
338
282
|
```vue
|
|
339
283
|
<script setup lang="ts">
|
|
340
284
|
import { InfiniteScrollV2 } from 'zx-infinite-scroll';
|
|
341
|
-
import 'zx-infinite-scroll/dist/style.css';
|
|
342
285
|
|
|
343
286
|
interface Item {
|
|
344
287
|
id: number;
|
|
@@ -372,7 +315,6 @@ const fetchData = async ({ page, pageSize }) => {
|
|
|
372
315
|
<script setup lang="ts">
|
|
373
316
|
import { ref } from 'vue';
|
|
374
317
|
import { InfiniteScrollV2 } from 'zx-infinite-scroll';
|
|
375
|
-
import 'zx-infinite-scroll/dist/style.css';
|
|
376
318
|
|
|
377
319
|
const keyword = ref('');
|
|
378
320
|
const category = ref('');
|
|
@@ -414,7 +356,6 @@ const fetchData = async ({ page, pageSize, keyword, category }) => {
|
|
|
414
356
|
```vue
|
|
415
357
|
<script setup lang="ts">
|
|
416
358
|
import { InfiniteScrollV2 } from 'zx-infinite-scroll';
|
|
417
|
-
import 'zx-infinite-scroll/dist/style.css';
|
|
418
359
|
|
|
419
360
|
const handleSuccess = ({ records, total, reset }) => {
|
|
420
361
|
console.log('加载成功', { records, total, reset });
|
|
@@ -453,7 +394,6 @@ const fetchData = async ({ page, pageSize }) => {
|
|
|
453
394
|
<script setup lang="ts">
|
|
454
395
|
import { ref } from 'vue';
|
|
455
396
|
import { InfiniteScroll } from 'zx-infinite-scroll';
|
|
456
|
-
import 'zx-infinite-scroll/dist/style.css';
|
|
457
397
|
|
|
458
398
|
const scrollRef = ref();
|
|
459
399
|
const list = ref([]);
|