Evan You vor 10 Jahren
Ursprung
Commit
5574af3da1
2 geänderte Dateien mit 9 neuen und 4 gelöschten Zeilen
  1. 1 4
      src/directives/public/el.js
  2. 8 0
      test/unit/specs/directives/public/ref_spec.js

+ 1 - 4
src/directives/public/el.js

@@ -5,10 +5,8 @@ module.exports = {
   priority: 1500,
 
   bind: function () {
+    /* istanbul ignore if */
     if (!this.arg) {
-      process.env.NODE_ENV !== 'production' && _.warn(
-        'v-el requires an argument.'
-      )
       return
     }
     var id = this.id = _.camelize(this.arg)
@@ -21,7 +19,6 @@ module.exports = {
   },
 
   unbind: function () {
-    if (!this.id) return
     var refs = (this._scope || this.vm).$els
     if (refs[this.id] === this.el) {
       refs[this.id] = null

+ 8 - 0
test/unit/specs/directives/public/ref_spec.js

@@ -115,5 +115,13 @@ if (_.inBrowser) {
         done()
       })
     })
+
+    it('warn when used on non-component node', function () {
+      new Vue({
+        el: el,
+        template: '<div v-ref:test></div>'
+      })
+      expect(hasWarned(_, 'must be used on a child component')).toBe(true)
+    })
   })
 }