Skip to content

Commit

Permalink
feat: support v-html for SVG elements (vuejs#8652)
Browse files Browse the repository at this point in the history
  • Loading branch information
Justineo authored and yyx990803 committed Dec 20, 2018
1 parent 22ad266 commit a981c80
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/platforms/web/runtime/modules/dom-props.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/* @flow */

import { isDef, isUndef, extend, toNumber } from 'shared/util'
import { isSVG } from 'web/util/index'

let svgContainer

function updateDOMProps (oldVnode: VNodeWithData, vnode: VNodeWithData) {
if (isUndef(oldVnode.data.domProps) && isUndef(vnode.data.domProps)) {
Expand Down Expand Up @@ -55,6 +58,17 @@ function updateDOMProps (oldVnode: VNodeWithData, vnode: VNodeWithData) {
if (shouldUpdateValue(elm, strCur)) {
elm.value = strCur
}
} else if (key === 'innerHTML' && isSVG(elm.tagName) && isUndef(elm.innerHTML)) {
// IE doesn't support innerHTML for SVG elements
svgContainer = svgContainer || document.createElement('div')
svgContainer.innerHTML = `<svg>${cur}</svg>`
const svg = svgContainer.firstChild
while (elm.firstChild) {
elm.removeChild(elm.firstChild)
}
while (svg.firstChild) {
elm.appendChild(svg.firstChild)
}
} else {
elm[key] = cur
}
Expand Down

0 comments on commit a981c80

Please sign in to comment.