Sfoglia il codice sorgente

add warning for mixing mustaches and v-bind for class

Evan You 10 anni fa
parent
commit
3d17807c8e
1 ha cambiato i file con 11 aggiunte e 0 eliminazioni
  1. 11 0
      src/compiler/compile.js

+ 11 - 0
src/compiler/compile.js

@@ -615,6 +615,17 @@ function compileDirectives (attrs, options) {
       value = textParser.tokensToExp(tokens)
       value = textParser.tokensToExp(tokens)
       arg = name
       arg = name
       pushDir('bind', publicDirectives.bind, true)
       pushDir('bind', publicDirectives.bind, true)
+      // warn against mixing mustaches with v-bind
+      if (process.env.NODE_ENV !== 'production') {
+        if (name === 'class' && Array.prototype.some.call(attrs, function (attr) {
+          return attr.name === ':class' || attr.name === 'v-bind:class'
+        })) {
+          _.warn(
+            name + '="' + rawValue + '": Do not mix mustache interpolation ' +
+            'and v-bind for "class" on the same element. Use one or the other.'
+          )
+        }
+      }
     } else
     } else
 
 
     // special attribute: transition
     // special attribute: transition