Przeglądaj źródła

implement ref warning

Evan You 10 lat temu
rodzic
commit
8c9c9a5825
2 zmienionych plików z 18 dodań i 6 usunięć
  1. 12 6
      src/directives/for.js
  2. 6 0
      src/directives/repeat.js

+ 12 - 6
src/directives/for.js

@@ -50,8 +50,14 @@ module.exports = {
     // check for trackby param
     // check for trackby param
     this.idKey = this._checkParam('track-by')
     this.idKey = this._checkParam('track-by')
 
 
+    // TODO: only check ref in 1.0.0
     // check v-ref
     // check v-ref
-    this.refId = this._checkParam(config.prefix + 'ref')
+    var ref = this._checkParam(config.prefix + 'ref')
+    /* istanbul ignore if */
+    if (process.env.NODE_ENV !== 'production') {
+      if (this.refID) _.deprecation.V_REF()
+    }
+    this.ref = ref || this._checkParam('ref')
 
 
     // check for transition stagger
     // check for transition stagger
     var stagger = +this._checkParam('stagger')
     var stagger = +this._checkParam('stagger')
@@ -67,7 +73,7 @@ module.exports = {
 
 
   update: function (data) {
   update: function (data) {
     this.diff(data)
     this.diff(data)
-    if (this.refId) {
+    if (this.ref) {
       this.updateRef()
       this.updateRef()
     }
     }
   },
   },
@@ -224,9 +230,9 @@ module.exports = {
 
 
   updateRef: function () {
   updateRef: function () {
     if (!this.converted) {
     if (!this.converted) {
-      this.vm.$[this.refId] = this.frags.map(findVmFromFrag)
+      this.vm.$[this.ref] = this.frags.map(findVmFromFrag)
     } else {
     } else {
-      var refs = this.vm.$[this.refId] = {}
+      var refs = this.vm.$[this.ref] = {}
       this.frags.forEach(function (frag) {
       this.frags.forEach(function (frag) {
         refs[frag.scope.$key] = findVmFromFrag(frag)
         refs[frag.scope.$key] = findVmFromFrag(frag)
       })
       })
@@ -472,8 +478,8 @@ module.exports = {
   },
   },
 
 
   unbind: function () {
   unbind: function () {
-    if (this.refId) {
-      this.vm.$[this.refId] = null
+    if (this.ref) {
+      this.vm.$[this.ref] = null
     }
     }
     if (this.frags) {
     if (this.frags) {
       var i = this.frags.length
       var i = this.frags.length

+ 6 - 0
src/directives/repeat.js

@@ -71,6 +71,12 @@ module.exports = {
     this.refID = this._checkParam(config.prefix + 'ref')
     this.refID = this._checkParam(config.prefix + 'ref')
     this.elID = this._checkParam(config.prefix + 'el')
     this.elID = this._checkParam(config.prefix + 'el')
 
 
+    if (process.env.NODE_ENV !== 'production') {
+      if (this.refID) _.deprecation.V_REF()
+      if (this.elID) _.deprecation.V_EL()
+    }
+    this.refID = this.refID || this._checkParam('ref')
+
     // check other directives that need to be handled
     // check other directives that need to be handled
     // at v-repeat level
     // at v-repeat level
     this.checkIf()
     this.checkIf()