Ver Fonte

copy attributes when replace:true

Evan You há 12 anos atrás
pai
commit
1d2c32d000
2 ficheiros alterados com 7 adições e 1 exclusões
  1. 6 0
      src/compiler.js
  2. 1 1
      test/unit/specs/api.js

+ 6 - 0
src/compiler.js

@@ -10,6 +10,7 @@ var Emitter     = require('./emitter'),
     
     // cache methods
     slice       = [].slice,
+    each        = [].forEach,
     log         = utils.log,
     makeHash    = utils.hash,
     extend      = utils.extend,
@@ -173,6 +174,11 @@ CompilerProto.setupElement = function (options) {
                 el.parentNode.insertBefore(replacer, el)
                 el.parentNode.removeChild(el)
             }
+            // copy over attributes
+            each.call(el.attributes, function (attr) {
+                replacer.setAttribute(attr.name, attr.value)
+            })
+            // replace
             el = replacer
         } else {
             el.appendChild(template.cloneNode(true))

+ 1 - 1
test/unit/specs/api.js

@@ -483,7 +483,7 @@ describe('UNIT: API', function () {
                     assert.strictEqual(t.$el.textContent, 'hi')
                     assert.strictEqual(t.$el.parentNode, parent)
                     var now = document.getElementById(testId)
-                    assert.strictEqual(now, null)
+                    assert.strictEqual(now, t.$el, 'should copy over attributes from replaced node')
                 })
 
                 it('should replace an off DOM Vue\'s $el', function () {