Skip to content

Commit a981c80

Browse files
Justineoyyx990803
authored andcommitted
feat: support v-html for SVG elements (#8652)
1 parent 22ad266 commit a981c80

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Diff for: src/platforms/web/runtime/modules/dom-props.js

+14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
/* @flow */
22

33
import { isDef, isUndef, extend, toNumber } from 'shared/util'
4+
import { isSVG } from 'web/util/index'
5+
6+
let svgContainer
47

58
function updateDOMProps (oldVnode: VNodeWithData, vnode: VNodeWithData) {
69
if (isUndef(oldVnode.data.domProps) && isUndef(vnode.data.domProps)) {
@@ -55,6 +58,17 @@ function updateDOMProps (oldVnode: VNodeWithData, vnode: VNodeWithData) {
5558
if (shouldUpdateValue(elm, strCur)) {
5659
elm.value = strCur
5760
}
61+
} else if (key === 'innerHTML' && isSVG(elm.tagName) && isUndef(elm.innerHTML)) {
62+
// IE doesn't support innerHTML for SVG elements
63+
svgContainer = svgContainer || document.createElement('div')
64+
svgContainer.innerHTML = `<svg>${cur}</svg>`
65+
const svg = svgContainer.firstChild
66+
while (elm.firstChild) {
67+
elm.removeChild(elm.firstChild)
68+
}
69+
while (svg.firstChild) {
70+
elm.appendChild(svg.firstChild)
71+
}
5872
} else {
5973
elm[key] = cur
6074
}

0 commit comments

Comments
 (0)