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 hefeng committed Jan 25, 2019
1 parent cacbbed commit 0e5cb3c
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 0e5cb3c

Please sign in to comment.