From beee252205b707ed100010a456f100af5323ea27 Mon Sep 17 00:00:00 2001 From: xujian Date: Sat, 6 Jan 2018 23:06:15 +0800 Subject: [PATCH] =?UTF-8?q?[bug=20fix]=20NoticeBar:=20=E5=B1=9E=E6=80=A7te?= =?UTF-8?q?xt=E4=B8=BA=E5=8A=A8=E6=80=81=E6=95=B0=E6=8D=AE=E4=B8=94?= =?UTF-8?q?=E4=BD=BF=E7=94=A8:text=E6=96=B9=E5=BC=8F=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E6=B7=BB=E5=8A=A0=E8=87=AA=E5=8A=A8=E6=BB=9A?= =?UTF-8?q?=E5=8A=A8=20(#515)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/notice-bar/index.vue | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/packages/notice-bar/index.vue b/packages/notice-bar/index.vue index 95ce23b79..1c8d333de 100644 --- a/packages/notice-bar/index.vue +++ b/packages/notice-bar/index.vue @@ -82,13 +82,12 @@ export default create({ }, mounted() { - const offsetWidth = this.$refs.content.getBoundingClientRect().width; - const wrapWidth = this.$refs.contentWrap.getBoundingClientRect().width; - if (this.scrollable && offsetWidth > wrapWidth) { - this.wrapWidth = wrapWidth; - this.offsetWidth = offsetWidth; - this.duration = offsetWidth / this.speed; - this.animationClass = 'van-notice-bar__play'; + this.initAnimation(); + }, + + watch: { + text: function() { + this.$nextTick(this.initAnimation); } }, @@ -102,6 +101,16 @@ export default create({ this.duration = (this.offsetWidth + this.wrapWidth) / this.speed; this.animationClass = 'van-notice-bar__play--infinite'; }); + }, + initAnimation() { + const offsetWidth = this.$refs.content.getBoundingClientRect().width; + const wrapWidth = this.$refs.contentWrap.getBoundingClientRect().width; + if (this.scrollable && offsetWidth > wrapWidth) { + this.wrapWidth = wrapWidth; + this.offsetWidth = offsetWidth; + this.duration = offsetWidth / this.speed; + this.animationClass = 'van-notice-bar__play'; + } } } });