改写city.vue页面,出现Cannot read property 'offsetWidth' of undefined
来源:12-7 城市列表组件改造(新路由语法)
慕UI5297780
2021-04-15
![图片描述](http://img.mukewang.com/szimg/6077e8d5094d45b107130899.jpg![图片描述](http://img.mukewang.com/szimg/6077e8d5094d45b107130899.jpg上图的第一个红框有问题,如果改成const element=itemRefs.value[letter],会报以下错误,每次点击一个字母就报一个错误,控制台输出console.log(itemRefs)结果如下,目前的问题是,无法引用点击的元素,希望老师能指导迷津
2回答
-
慕UI5297780
提问者
2021-04-15
代码在better-scroll.esm.js文件的2262行中,下面是部分代码,offsetWidth在加粗那一行
Scroller.prototype.scrollToElement = function (el, time, offsetX, offsetY, easing) {
var targetEle = getElement(el);
var pos = offset(targetEle);
var getOffset = function (offset, size, wrapperSize) {
if (typeof offset === 'number') {
return offset;
}
// if offsetX/Y are true we center the element to the screen
return offset ? Math.round(size / 2 - wrapperSize / 2) : 0;
};
offsetX = getOffset(offsetX, targetEle.offsetWidth, this.wrapper.offsetWidth);
offsetY = getOffset(offsetY, targetEle.offsetHeight, this.wrapper.offsetHeight);
var getPos = function (pos, wrapperPos, offset, scrollBehavior) {
pos -= wrapperPos;
pos = scrollBehavior.adjustPosition(pos - offset);
return pos;
};
pos.left = getPos(pos.left, this.wrapperOffset.left, offsetX, this.scrollBehaviorX);
pos.top = getPos(pos.top, this.wrapperOffset.top, offsetY, this.scrollBehaviorY);
if (this.hooks.trigger(this.hooks.eventTypes.scrollToElement, targetEle, pos)) {
return;
}
this.scrollTo(pos.left, pos.top, time, easing);
};
Scroller.prototype.resetPosition = function (time, easing) {
if (time === void 0) { time = 0; }
if (easing === void 0) { easing = ease.bounce; }
var _a = this.scrollBehaviorX.checkInBoundary(), x = _a.position, xInBoundary = _a.inBoundary;
var _b = this.scrollBehaviorY.checkInBoundary(), y = _b.position, yInBoundary = _b.inBoundary;
if (xInBoundary && yInBoundary) {
return false;
}
/* istanbul ignore if */
if (isIOSBadVersion) {
// fix ios 13.4 bouncing
// see it in issues 982
this.reflow();
}
// out of boundary
this.scrollTo(x, y, time, easing);
return true;
};
032021-04-20 -
Dell
2021-04-15
offsetWidth 对应的代码在哪里?
00
相似问题
回答 1