8000 fix SVG class interpolation regression (fix #2035) · Hsinwe/vue@aec06da · GitHub
[go: up one dir, main page]

Skip to content

Commit aec06da

Browse files
committed
fix SVG class interpolation regression (fix vuejs#2035)
1 parent a51be5f commit aec06da

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

src/directive.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import {
77
getBindAttr,
88
camelize,
99
nextTick,
10-
warn
10+
warn,
11+
setClass
1112
} from './util/index'
1213
import Watcher from './watcher'
1314
import { removeTags } from './parsers/text'
@@ -88,9 +89,10 @@ Directive.prototype._bind = function () {
8889
} else {
8990
// for class interpolations, only remove the parts that
9091
// need to be interpolated.
91-
this.el.className = removeTags(this.el.className)
92-
.trim()
93-
.replace(/\s+/g, ' ')
92+
setClass(
93+
this.el,
94+
removeTags(this.el.getAttribute('class')).trim().replace(/\s+/g, ' ')
95+
)
9496
}
9597
}
9698

src/util/dom.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ export function off (el, event, cb) {
188188
* @param {String} cls
189189
*/
190190

191-
function setClass (el, cls) {
191+
export function setClass (el, cls) {
192192
/* istanbul ignore if */
193193
if (isIE9 && !(el instanceof SVGElement)) {
194194
el.className = cls

test/unit/specs/misc_spec.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,4 +401,19 @@ describe('Misc', function () {
401401
})
402402
expect(vm.$el.firstChild.className).toBe('outer inner')
403403
})
404+
405+
it('SVG class interpolation', function () {
406+
var vm = new Vue({
407+
el: document.createElement('div'),
408+
template: '<icon class="abc" icon="def"></icon>',
409+
components: {
410+
icon: {
411+
props: ['class', 'icon'],
412+
replace: true,
413+
template: '<svg class="si-icon {{icon}} {{class}}"><use xlink:href=""></use></svg>'
414+
}
415+
}
416+
})
417+
expect(vm.$el.firstChild.getAttribute('class')).toBe('si-icon abc def')
418+
})
404419
})

0 commit comments

Comments
 (0)
0