From 8424b51affaf9820c1496b4289dc46372e73d62d Mon Sep 17 00:00:00 2001 From: neverland Date: Thu, 10 May 2018 20:41:15 +0800 Subject: [PATCH] [Improvement] NoticeBar: add ref check (#1037) --- packages/notice-bar/index.vue | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/notice-bar/index.vue b/packages/notice-bar/index.vue index 2006847bc..eabe9c5e0 100644 --- a/packages/notice-bar/index.vue +++ b/packages/notice-bar/index.vue @@ -90,8 +90,13 @@ export default create({ text: { handler() { this.$nextTick(() => { - const offsetWidth = this.$refs.content.getBoundingClientRect().width; - const wrapWidth = this.$refs.wrap.getBoundingClientRect().width; + const { wrap, content } = this.$refs; + if (!wrap || !content) { + return; + } + + const wrapWidth = wrap.getBoundingClientRect().width; + const offsetWidth = content.getBoundingClientRect().width; if (this.scrollable && offsetWidth > wrapWidth) { this.wrapWidth = wrapWidth; this.offsetWidth = offsetWidth;