Просмотр исходного кода

handle bind-name for partials and warn old usage

Evan You 10 лет назад
Родитель
Сommit
c90f213a81
2 измененных файлов с 24 добавлено и 8 удалено
  1. 7 0
      src/deprecations.js
  2. 17 8
      src/element-directives/partial.js

+ 7 - 0
src/deprecations.js

@@ -158,6 +158,13 @@ if (process.env.NODE_ENV !== 'production') {
       )
       )
     },
     },
 
 
+    PARTIAL_NAME: function (id) {
+      wanr(
+        '<partial name="' + id + '">: mustache interpolations inside attributes ' +
+        'will be deprecated in 1.0.0. Use bind-name="expression" instead.'
+      )
+    },
+
     REF_IN_CHILD: function () {
     REF_IN_CHILD: function () {
       warn(
       warn(
         'v-ref or ref can no longer be used on a component root in its own ' +
         'v-ref or ref can no longer be used on a component root in its own ' +

+ 17 - 8
src/element-directives/partial.js

@@ -10,19 +10,28 @@ module.exports = {
     this.anchor = _.createAnchor('v-partial')
     this.anchor = _.createAnchor('v-partial')
     _.replace(el, this.anchor)
     _.replace(el, this.anchor)
     var id = el.getAttribute('name')
     var id = el.getAttribute('name')
-    var tokens = textParser.parse(id)
-    if (tokens) {
-      // dynamic partial
-      this.setupDynamic(tokens)
+    if (id != null) {
+      var tokens = textParser.parse(id)
+      if (tokens) {
+        // dynamic partial
+        this.setupDynamic(textParser.tokensToExp(tokens))
+        if (process.env.NODE_ENV !== 'production') {
+          _.deprecation.PARTIAL_NAME(id)
+        }
+      } else {
+        // static partial
+        this.insert(id)
+      }
     } else {
     } else {
-      // static partial
-      this.insert(id)
+      id = el.getAttribute('bind-name')
+      if (id) {
+        this.setupDynamic(id)
+      }
     }
     }
   },
   },
 
 
-  setupDynamic: function (tokens) {
+  setupDynamic: function (exp) {
     var self = this
     var self = this
-    var exp = textParser.tokensToExp(tokens)
     this.unwatch = this.vm.$watch(exp, function (value) {
     this.unwatch = this.vm.$watch(exp, function (value) {
       vIf.remove.call(self)
       vIf.remove.call(self)
       self.insert(value)
       self.insert(value)