Răsfoiți Sursa

better warning messages

Evan You 12 ani în urmă
părinte
comite
fe27197071
4 a modificat fișierele cu 20 adăugiri și 7 ștergeri
  1. 9 2
      src/compiler.js
  2. 2 2
      src/directive.js
  3. 8 2
      src/directives/if.js
  4. 1 1
      src/directives/on.js

+ 9 - 2
src/compiler.js

@@ -370,7 +370,11 @@ CompilerProto.compile = function (node, root) {
  */
 CompilerProto.checkPriorityDir = function (dirname, node, root) {
     var expression, directive, Ctor
-    if (dirname === 'component' && root !== true && (Ctor = this.resolveComponent(node, undefined, true))) {
+    if (
+        dirname === 'component' &&
+        root !== true &&
+        (Ctor = this.resolveComponent(node, undefined, true))
+    ) {
         directive = Directive.parse(dirname, '', this, node)
         directive.Ctor = Ctor
     } else {
@@ -379,7 +383,10 @@ CompilerProto.checkPriorityDir = function (dirname, node, root) {
     }
     if (directive) {
         if (root === true) {
-            utils.warn('Directive v-' + dirname + ' cannot be used on manually instantiated root node.')
+            utils.warn(
+                'Directive v-' + dirname + ' cannot be used on an already instantiated ' +
+                'VM\'s root node. Use it from the parent\'s template instead.'
+            )
             return
         }
         this.deferred.push(directive)

+ 2 - 2
src/directive.js

@@ -191,7 +191,7 @@ Directive.parse = function (dirname, expression, compiler, node) {
 
     var dir = compiler.getOption('directives', dirname) || directives[dirname]
     if (!dir) {
-        utils.warn('unknown directive: ' + dirname)
+        utils.warn('Unknown directive: ' + dirname)
         return
     }
 
@@ -209,7 +209,7 @@ Directive.parse = function (dirname, expression, compiler, node) {
     if (rawKey || expression === '') {
         return new Directive(dirname, dir, expression, rawKey, compiler, node)
     } else {
-        utils.warn('invalid directive expression: ' + expression)
+        utils.warn('Invalid directive expression: ' + expression)
     }
 }
 

+ 8 - 2
src/directives/if.js

@@ -13,10 +13,16 @@ module.exports = {
         this.parent.removeChild(this.el)
 
         if (utils.attr(this.el, 'view')) {
-            utils.warn('Conflict: v-if cannot be used together with v-view')
+            utils.warn(
+                'Conflict: v-if cannot be used together with v-view. ' +
+                'Just set v-view\'s binding value to empty string to empty it.'
+            )
         }
         if (utils.attr(this.el, 'repeat')) {
-            utils.warn('Conflict: v-if cannot be used together with v-repeat')
+            utils.warn(
+                'Conflict: v-if cannot be used together with v-repeat. ' +
+                'Use `v-show` or the `filterBy` filter instead.'
+            )
         }
     },
 

+ 1 - 1
src/directives/on.js

@@ -12,7 +12,7 @@ module.exports = {
 
     update: function (handler) {
         if (typeof handler !== 'function') {
-            utils.warn('Directive "on" expects a function value.')
+            utils.warn('Directive "v-on:' + this.expression + '" expects a method.')
             return
         }
         this._unbind()