Evan You 10 лет назад
Родитель
Сommit
9fc006871c

+ 2 - 5
src/compiler/compile-props.js

@@ -50,11 +50,8 @@ module.exports = function compileProps (el, propOptions) {
 
     // first check literal version
     attr = _.hyphenate(name)
-    value = prop.raw = el.getAttribute(attr)
-    if (value !== null) {
-      el.removeAttribute(attr)
-    } else {
-
+    value = prop.raw = _.attr(el, attr)
+    if (value === null) {
       // then check dynamic version
       if ((value = _.getBindAttr(el, attr)) === null) {
         if ((value = _.getBindAttr(el, attr + '.sync')) !== null) {

+ 1 - 1
src/compiler/compile.js

@@ -490,7 +490,7 @@ function checkComponent (el, options) {
 
 function checkTerminalDirectives (el, options) {
   // skip v-pre
-  if (_.attr(el, 'pre') !== null) {
+  if (_.attr(el, 'v-pre') !== null) {
     return skip
   }
   // skip v-else block, but only if following v-if

+ 1 - 2
src/directive.js

@@ -160,9 +160,8 @@ Directive.prototype._checkStatement = function () {
  */
 
 Directive.prototype.param = function (name) {
-  var param = this.el.getAttribute(name)
+  var param = _.attr(this.el, name)
   if (param != null) {
-    this.el.removeAttribute(name)
     param = (this._scope || this.vm).$interpolate(param)
   } else {
     param = _.getBindAttr(this.el, name)

+ 1 - 1
src/directives/public/if.js

@@ -10,7 +10,7 @@ module.exports = {
     if (!el.__vue__) {
       // check else block
       var next = el.nextElementSibling
-      if (next && _.attr(next, 'else') !== null) {
+      if (next && _.attr(next, 'v-else') !== null) {
         _.remove(next)
         this.elseFactory = new FragmentFactory(this.vm, next)
       }

+ 1 - 1
src/directives/public/show.js

@@ -6,7 +6,7 @@ module.exports = {
   bind: function () {
     // check else block
     var next = this.el.nextElementSibling
-    if (next && _.attr(next, 'else') !== null) {
+    if (next && _.attr(next, 'v-else') !== null) {
       this.elseEl = next
     }
   },

+ 1 - 2
src/util/component.js

@@ -44,9 +44,8 @@ exports.checkComponent = function (el, options) {
 
 function getIsBinding (el) {
   // dynamic syntax
-  var exp = el.getAttribute('is')
+  var exp = _.attr(el, 'is')
   if (exp != null) {
-    el.removeAttribute('is')
     return { id: exp }
   } else {
     exp = _.getBindAttr(el, 'is')

+ 3 - 9
src/util/dom.js

@@ -42,14 +42,13 @@ exports.inDoc = function (node) {
 }
 
 /**
- * Extract an attribute from a node.
+ * Get and remove an attribute from a node.
  *
  * @param {Node} node
  * @param {String} attr
  */
 
 exports.attr = function (node, attr) {
-  attr = 'v-' + attr
   var val = node.getAttribute(attr)
   if (val !== null) {
     node.removeAttribute(attr)
@@ -66,14 +65,9 @@ exports.attr = function (node, attr) {
  */
 
 exports.getBindAttr = function (node, name) {
-  var attr = ':' + name
-  var val = node.getAttribute(attr)
+  var val = exports.attr(node, ':' + name)
   if (val === null) {
-    attr = 'v-bind:' + name
-    val = node.getAttribute(attr)
-  }
-  if (val !== null) {
-    node.removeAttribute(attr)
+    val = exports.attr(node, 'v-bind:' + name)
   }
   return val
 }

+ 1 - 1
test/unit/specs/util/dom_spec.js

@@ -27,7 +27,7 @@ if (_.inBrowser) {
 
     it('attr', function () {
       target.setAttribute('v-test', 'ok')
-      var val = _.attr(target, 'test')
+      var val = _.attr(target, 'v-test')
       expect(val).toBe('ok')
       expect(target.hasAttribute('v-test')).toBe(false)
     })