Revert "feat: 使用 radash 的 throttle 包装 load 函数,优化加载频率并重构 refresh 方法"
This reverts commit 40bf214da7
.
This commit is contained in:
@ -1,6 +1,4 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { throttle } from 'radash';
|
|
||||||
|
|
||||||
function checkIsVisible(el: Element, root: Element | null = null) {
|
function checkIsVisible(el: Element, root: Element | null = null) {
|
||||||
if (!el) return false;
|
if (!el) return false;
|
||||||
|
|
||||||
@ -45,12 +43,19 @@ defineSlots<{
|
|||||||
// 加载失败
|
// 加载失败
|
||||||
error(props: { retry: () => void }): unknown;
|
error(props: { retry: () => void }): unknown;
|
||||||
}>();
|
}>();
|
||||||
|
defineExpose({
|
||||||
|
refresh: () => {
|
||||||
|
currentPage = 0;
|
||||||
|
state.value = '';
|
||||||
|
return load('refresh');
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
const target = ref(null);
|
const target = ref(null);
|
||||||
let currentPage = 0;
|
let currentPage = 0;
|
||||||
const state = ref<'' | 'loading' | 'loaded' | 'complete' | 'error'>('');
|
const state = ref<'' | 'loading' | 'loaded' | 'complete' | 'error'>('');
|
||||||
|
|
||||||
const loadImpl = async (why?: string) => {
|
const load = async (why?: string) => {
|
||||||
console.group('load');
|
console.group('load');
|
||||||
console.debug(`why :>> `, why);
|
console.debug(`why :>> `, why);
|
||||||
console.groupEnd();
|
console.groupEnd();
|
||||||
@ -76,19 +81,6 @@ const loadImpl = async (why?: string) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 使用radash的throttle包装load函数,1秒内最多执行一次
|
|
||||||
const load = throttle({ interval: 1000 }, loadImpl);
|
|
||||||
|
|
||||||
const refresh = () => {
|
|
||||||
currentPage = 0;
|
|
||||||
state.value = '';
|
|
||||||
return loadImpl('refresh'); // refresh 不需要节流
|
|
||||||
};
|
|
||||||
|
|
||||||
defineExpose({
|
|
||||||
refresh,
|
|
||||||
});
|
|
||||||
|
|
||||||
const { pause, resume /* ,isSupported, isActive */ } = useIntersectionObserver(
|
const { pause, resume /* ,isSupported, isActive */ } = useIntersectionObserver(
|
||||||
target,
|
target,
|
||||||
([entry]) => {
|
([entry]) => {
|
||||||
|
Reference in New Issue
Block a user