Explorar el Código

set property in v-attr

Evan You hace 11 años
padre
commit
68bde05982
Se han modificado 2 ficheros con 11 adiciones y 0 borrados
  1. 3 0
      src/directives/attr.js
  2. 8 0
      test/unit/specs/directives/attr_spec.js

+ 3 - 0
src/directives/attr.js

@@ -44,6 +44,9 @@ module.exports = {
     } else {
       this.el.removeAttribute(attr)
     }
+    if (attr in this.el) {
+      this.el[attr] = value
+    }
   }
 
 }

+ 8 - 0
test/unit/specs/directives/attr_spec.js

@@ -26,6 +26,14 @@ if (_.inBrowser) {
       expect(el.getAttribute('test')).toBe('0')
     })
 
+    it('should set property', function () {
+      dir.el = document.createElement('input')
+      dir.arg = 'value'
+      dir.update('what')
+      expect(dir.el.getAttribute('value')).toBe('what')
+      expect(dir.el.value).toBe('what')
+    })
+
     it('xlink', function () {
       var xlinkNS = 'http://www.w3.org/1999/xlink'
       dir.arg = 'xlink:special'