diff --git a/lib/template-compiler/modules/transform-srcset.js b/lib/template-compiler/modules/transform-srcset.js index 49a15585b..2779eeae6 100644 --- a/lib/template-compiler/modules/transform-srcset.js +++ b/lib/template-compiler/modules/transform-srcset.js @@ -28,10 +28,15 @@ function transform (node) { return { require: urlToRequire(url), descriptor: descriptor } }) - let code = '' - imageCandidates.forEach((o, i, a) => { - code += o.require + ' + " ' + o.descriptor + (i < a.length - 1 ? ', " + ' : '"') - }) + // "require(url1)" + // "require(url1) 1x" + // "require(url1), require(url2)" + // "require(url1), require(url2) 2x" + // "require(url1) 1x, require(url2)" + // "require(url1) 1x, require(url2) 2x" + const code = imageCandidates.map( + ({ require, descriptor }) => `${require} + "${descriptor ? ' ' + descriptor : ''}, " + ` + ).join('').slice(0, -6).concat('"').replace(/ \+ ""$/, '') attr.value = code } diff --git a/test/fixtures/transform.vue b/test/fixtures/transform.vue index 1e358f890..f43b47c69 100644 --- a/test/fixtures/transform.vue +++ b/test/fixtures/transform.vue @@ -4,8 +4,12 @@ + + + +