Przeglądaj źródła

fix domProps unset for v-html (fix #4107)

Evan You 9 lat temu
rodzic
commit
d0afcd3cf9

+ 4 - 1
src/core/vdom/patch.js

@@ -78,7 +78,10 @@ export function createPatchFunction (backend) {
 
   function removeElement (el) {
     const parent = nodeOps.parentNode(el)
-    nodeOps.removeChild(parent, el)
+    // element may have already been removed due to v-html
+    if (parent) {
+      nodeOps.removeChild(parent, el)
+    }
   }
 
   function createElm (vnode, insertedVnodeQueue, nested) {

+ 1 - 1
src/platforms/web/runtime/modules/dom-props.js

@@ -17,7 +17,7 @@ function updateDOMProps (oldVnode: VNodeWithData, vnode: VNodeWithData) {
 
   for (key in oldProps) {
     if (props[key] == null) {
-      elm[key] = undefined
+      elm[key] = ''
     }
   }
   for (key in props) {

+ 1 - 1
test/unit/modules/vdom/modules/dom-props.spec.js

@@ -22,7 +22,7 @@ describe('vdom domProps module', () => {
     const vnode2 = new VNode('a', { domProps: {}})
     patch(null, vnode1)
     const elm = patch(vnode1, vnode2)
-    expect(elm.src).toBeUndefined()
+    expect(elm.src).toBe('')
   })
 
   it('should initialize the elements value to zero', () => {