Skip to content

Commit 66c244d

Browse files
committed
fix img src resolution with compiler beta.6
1 parent e12440b commit 66c244d

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

lib/template-compiler.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,25 @@ var options = {
99
modules: [{
1010
postTransformNode (el) {
1111
if (el.tag === 'img') {
12-
el.staticAttrs && el.staticAttrs.some(rewrite)
12+
el.attrs && el.attrs.some(rewrite)
1313
}
1414
}
1515
}]
1616
}
1717

1818
function rewrite (attr) {
1919
if (attr.name === 'src') {
20-
var firstChar = attr.value.charAt(1)
20+
var value = attr.value
21+
var isStatic = value.charAt(0) === '"' && value.charAt(value.length - 1) === '"'
22+
if (!isStatic) {
23+
return
24+
}
25+
var firstChar = value.charAt(1)
2126
if (firstChar === '.' || firstChar === '~') {
2227
if (firstChar === '~') {
23-
attr.value = '"' + attr.value.slice(2)
28+
value = '"' + value.slice(2)
2429
}
25-
attr.value = `require(${attr.value})`
30+
attr.value = `require(${value})`
2631
}
2732
return true
2833
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"source-map": "^0.5.6",
4141
"vue-hot-reload-api": "^2.0.1",
4242
"vue-style-loader": "^1.0.0",
43-
"vue-template-compiler": "^2.0.0-alpha.8"
43+
"vue-template-compiler": "^2.0.0-beta.6"
4444
},
4545
"peerDependencies": {
4646
"css-loader": "^0.23.1"

0 commit comments

Comments
 (0)