From 5840fc8d9e85a8bad6da40ed82428e6d211e0f43 Mon Sep 17 00:00:00 2001 From: Justineo Date: Tue, 14 Aug 2018 16:55:42 +0800 Subject: [PATCH] feat: support v-html for SVG elements --- src/platforms/web/runtime/modules/dom-props.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/platforms/web/runtime/modules/dom-props.js b/src/platforms/web/runtime/modules/dom-props.js index f3888aed066..b95715be975 100644 --- a/src/platforms/web/runtime/modules/dom-props.js +++ b/src/platforms/web/runtime/modules/dom-props.js @@ -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)) { @@ -44,6 +47,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 = `${cur}` + const svg = svgContainer.firstChild + while (elm.firstChild) { + elm.removeChild(elm.firstChild) + } + while (svg.firstChild) { + elm.appendChild(svg.firstChild) + } } else { elm[key] = cur }