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;