ncaught TypeError: Cannot read property 'offsetWidth' of undefined在使用iview表单的时候发生了错误var navWidth = this.$refs.nav.offsetWidth;
控制台报错:Uncaught TypeError: Cannot read property 'offsetWidth' of undefined
at VueComponent.updateNavScroll (iview.js?7687:24282)
sources:
updateNavScroll: function updateNavScroll() {
var navWidth = this.$refs.nav.offsetWidth;
var containerWidth = this.$refs.navScroll.offsetWidth;
var currentOffset = this.getCurrentScrollOffset();
if (containerWidth < navWidth) {
this.scrollable = true;
if (navWidth - currentOffset < containerWidth) {
this.setOffset(navWidth - containerWidth);
}
} else {
this.scrollable = false;
if (currentOffset > 0) {
this.setOffset(0);
}
}
},### 题目描述
题目来源及自己的思路
相关代码
// 请把代码文本粘贴到下方(请勿用图片代替代码)
检查
this.$refs.navScroll
,这个可能并不是一个dom,或者这个的值时undefined