Bladeren bron

remove attributes at link time instead of compile

Evan You 11 jaren geleden
bovenliggende
commit
21c011e1fe
3 gewijzigde bestanden met toevoegingen van 4 en 7 verwijderingen
  1. 0 3
      src/compile/compile.js
  2. 4 0
      src/directive.js
  3. 0 4
      test/unit/specs/compile/compile_spec.js

+ 0 - 3
src/compile/compile.js

@@ -460,9 +460,6 @@ function collectDirectives (el, options, asParent) {
       dirDef = options.directives[dirName]
       _.assertAsset(dirDef, 'directive', dirName)
       if (dirDef) {
-        if (dirName !== 'cloak') {
-          el.removeAttribute(attrName)
-        }
         dirs.push({
           name: dirName,
           descriptors: dirParser.parse(attr.value),

+ 4 - 0
src/directive.js

@@ -1,4 +1,5 @@
 var _ = require('./util')
+var config = require('./config')
 var Watcher = require('./watcher')
 var textParser = require('./parse/text')
 var expParser = require('./parse/expression')
@@ -50,6 +51,9 @@ var p = Directive.prototype
  */
 
 p._bind = function (def) {
+  if (this.name !== 'cloak' && this.el.removeAttribute) {
+    this.el.removeAttribute(config.prefix + this.name)
+  }
   if (typeof def === 'function') {
     this.update = def
   } else {

+ 0 - 4
test/unit/specs/compile/compile_spec.js

@@ -50,10 +50,6 @@ if (_.inBrowser) {
       })
       var linker = compile(el, options)
       expect(typeof linker).toBe('function')
-      // should remove attributes
-      expect(el.attributes.length).toBe(0)
-      expect(el.firstChild.attributes.length).toBe(0)
-      expect(el.lastChild.attributes.length).toBe(0)
       linker(vm, el)
       expect(vm._bindDir.calls.count()).toBe(4)
       expect(vm._bindDir).toHaveBeenCalledWith('a', el, descriptorB, defA)