From 0712d920634e7b70b77f49c71337172bf3ece470 Mon Sep 17 00:00:00 2001 From: chenjiahan Date: Wed, 11 Nov 2020 22:43:36 +0800 Subject: [PATCH] perf(NoticeBar): avoid repeated start --- src/notice-bar/index.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/notice-bar/index.js b/src/notice-bar/index.js index 775bbf0d4..f7b14ca73 100644 --- a/src/notice-bar/index.js +++ b/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'; @@ -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;