Skip to content

Commit 8099391

Browse files
committed
fix: spin error #6222
1 parent 7939eb1 commit 8099391

File tree

2 files changed

+13
-24
lines changed

2 files changed

+13
-24
lines changed

components/spin/Spin.tsx

+12-24
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { VNode, ExtractPropTypes, PropType } from 'vue';
2-
import { cloneVNode, isVNode, defineComponent, shallowRef, watch } from 'vue';
3-
import debounce from 'lodash-es/debounce';
2+
import { onBeforeUnmount, cloneVNode, isVNode, defineComponent, shallowRef, watch } from 'vue';
3+
import { debounce } from 'throttle-debounce';
44
import PropTypes from '../_util/vue-types';
55
import { filterEmpty, getPropsSlot } from '../_util/props-util';
66
import initDefaultProps from '../_util/props-util/initDefaultProps';
@@ -44,37 +44,25 @@ export default defineComponent({
4444
setup(props, { attrs, slots }) {
4545
const { prefixCls, size, direction } = useConfigInject('spin', props);
4646
const [wrapSSR, hashId] = useStyle(prefixCls);
47-
const sSpinning = shallowRef(props.spinning && shouldDelay(props.spinning, props.delay));
47+
const sSpinning = shallowRef(props.spinning && !shouldDelay(props.spinning, props.delay));
4848
let updateSpinning: any;
49-
function originalUpdateSpinning() {
50-
if (sSpinning.value !== props.spinning) {
51-
sSpinning.value = props.spinning;
52-
}
53-
}
54-
function cancelExistingSpin() {
55-
if (updateSpinning && updateSpinning.cancel) {
56-
updateSpinning.cancel();
57-
}
58-
}
59-
function debouncifyUpdateSpinning() {
60-
const { delay } = props;
61-
if (delay) {
62-
cancelExistingSpin();
63-
updateSpinning = debounce(originalUpdateSpinning, delay);
64-
} else {
65-
updateSpinning = originalUpdateSpinning;
66-
}
67-
}
6849
watch(
69-
() => [props.spinning, props.delay],
50+
[() => props.spinning, () => props.delay],
7051
() => {
71-
debouncifyUpdateSpinning();
52+
updateSpinning?.cancel();
53+
updateSpinning = debounce(props.delay, () => {
54+
sSpinning.value = props.spinning;
55+
});
7256
updateSpinning?.();
7357
},
7458
{
7559
immediate: true,
60+
flush: 'post',
7661
},
7762
);
63+
onBeforeUnmount(() => {
64+
updateSpinning?.cancel();
65+
});
7866
return () => {
7967
const { class: cls, ...divProps } = attrs;
8068
const { tip = slots.tip?.() } = props;

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@
292292
"scroll-into-view-if-needed": "^2.2.25",
293293
"shallow-equal": "^1.0.0",
294294
"stylis": "^4.1.3",
295+
"throttle-debounce": "^5.0.0",
295296
"vue-types": "^3.0.0",
296297
"warning": "^4.0.0"
297298
},

0 commit comments

Comments
 (0)