Evan You 10 лет назад
Родитель
Сommit
6fc97fc6b9
1 измененных файлов с 10 добавлено и 6 удалено
  1. 10 6
      src/runtime/vdom/modules/attrs.js

+ 10 - 6
src/runtime/vdom/modules/attrs.js

@@ -10,18 +10,19 @@ const isBooleanAttr = makeMap(
   'truespeed,typemustmatch,visible'
 )
 
+const xlinkNS = 'http://www.w3.org/1999/xlink'
+const isXlink = name => name.slice(0, 6) === 'xlink:'
+
 function updateAttrs (oldVnode, vnode) {
   let key, cur, old
   const elm = vnode.elm
   const oldAttrs = oldVnode.data.attrs || {}
   const attrs = vnode.data.attrs || {}
 
-  // update modified attributes, add new attributes
   for (key in attrs) {
     cur = attrs[key]
     old = oldAttrs[key]
     if (old !== cur) {
-      // TODO: add support to namespaced attributes (setAttributeNS)
       if (isBooleanAttr(key)) {
         if (cur == null) {
           elm.removeAttribute(key)
@@ -30,17 +31,20 @@ function updateAttrs (oldVnode, vnode) {
         }
       } else if (isEnumeratedAttr(key)) {
         elm.setAttribute(key, cur == null ? 'false' : 'true')
+      } else if (isXlink(key)) {
+        elm.setAttributeNS(xlinkNS, key, cur)
       } else {
         elm.setAttribute(key, cur)
       }
     }
   }
-  // remove removed attributes
-  // use `in` operator since the previous `for` iteration uses it (.i.e. add even attributes with undefined value)
-  // the other option is to remove all attributes with value == undefined
   for (key in oldAttrs) {
     if (attrs[key] == null) {
-      elm.removeAttribute(key)
+      if (isXlink(key)) {
+        elm.removeAttributeNS(xlinkNS, key)
+      } else {
+        elm.removeAttribute(key)
+      }
     }
   }
 }