Skip to content

Commit

Permalink
perf(NoticeBar): avoid repeated start
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan committed Nov 11, 2020
1 parent 599e817 commit 0712d92
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/notice-bar/index.js
@@ -1,8 +1,14 @@
import { ref, watch, reactive, onActivated } from 'vue';
import { ref, watch, reactive } from 'vue';
import { isDef, createNamespace } from '../utils';

// Composition
import { raf, useRect, doubleRaf, useEventListener } from '@vant/use';
import {
raf,
useRect,
doubleRaf,
useEventListener,
onMountedOrActivated,
} from '@vant/use';

// Components
import Icon from '../icon';
Expand Down Expand Up @@ -159,15 +165,13 @@ export default createComponent({
}, ms);
};

onActivated(start);
onMountedOrActivated(start);

// fix cache issues with forwards and back history in safari
// see: https://guwii.com/cache-issues-with-forwards-and-back-history-in-safari/
useEventListener('pageshow', start);

watch([() => props.text, () => props.scrollable], start, {
immediate: true,
});
watch([() => props.text, () => props.scrollable], start);

return () => {
const { color, wrapable, background } = props;
Expand Down

0 comments on commit 0712d92

Please sign in to comment.