fix: carousel not work with variable-width #3977

pull/4013/head
tangjinzhou 2021-04-27 22:30:17 +08:00
parent 5eeaaae08c
commit 58ffdd9728
4 changed files with 4 additions and 6 deletions

View File

@ -116,7 +116,7 @@ export default {
slideCount: children.length, slideCount: children.length,
}); });
children.forEach(child => { children.forEach(child => {
const childWidth = child.props.width.split('px')[0]; const childWidth = child.props.style?.width?.split('px')[0] || 0;
childrenWidths.push(childWidth); childrenWidths.push(childWidth);
trackWidth += childWidth; trackWidth += childWidth;
}); });

View File

@ -155,7 +155,7 @@ export default defineComponent({
for (let j = i; j < i + settings.rows * settings.slidesPerRow; j += settings.slidesPerRow) { for (let j = i; j < i + settings.rows * settings.slidesPerRow; j += settings.slidesPerRow) {
const row = []; const row = [];
for (let k = j; k < j + settings.slidesPerRow; k += 1) { for (let k = j; k < j + settings.slidesPerRow; k += 1) {
if (settings.variableWidth && children[k].props.style) { if (settings.variableWidth && children[k].props?.style) {
currentWidth = children[k].props.style.width; currentWidth = children[k].props.style.width;
} }
if (k >= children.length) break; if (k >= children.length) break;

2
v2-doc

@ -1 +1 @@
Subproject commit 31d85319dcc0438b3c80957c99f57b931b047c11 Subproject commit ee89a33312a7bb5c65c6080c12613b9ca1474aaf

View File

@ -118,9 +118,7 @@ module.exports = {
use: [ use: [
{ {
loader: MiniCssExtractPlugin.loader, loader: MiniCssExtractPlugin.loader,
options: { options: {},
hmr: true,
},
}, },
'css-loader', 'css-loader',
], ],