Selaa lähdekoodia

make dynamic resolving built-in for custom literal directives

Evan You 12 vuotta sitten
vanhempi
commit
83def445ee
3 muutettua tiedostoa jossa 10 lisäystä ja 6 poistoa
  1. 5 2
      src/directive.js
  2. 4 3
      src/directives/index.js
  3. 1 1
      src/directives/partial.js

+ 5 - 2
src/directive.js

@@ -48,8 +48,11 @@ function Directive (definition, expression, rawKey, compiler, node) {
         return
     }
 
-    this.expression = expression.trim()
-    this.rawKey     = rawKey
+    this.expression = (
+        this.isLiteral
+            ? compiler.eval(expression)
+            : expression
+    ).trim()
     
     parseKey(this, rawKey)
 

+ 4 - 3
src/directives/index.js

@@ -68,14 +68,15 @@ module.exports = {
     ref: {
         isLiteral: true,
         bind: function () {
-            var id = this.id = this.compiler.eval(this.expression)
+            var id = this.expression
             if (id) {
                 this.vm.$parent.$[id] = this.vm
             }
         },
         unbind: function () {
-            if (this.id) {
-                delete this.vm.$parent.$[this.id]
+            var id = this.expression
+            if (id) {
+                delete this.vm.$parent.$[id]
             }
         }
     }

+ 1 - 1
src/directives/partial.js

@@ -7,7 +7,7 @@ module.exports = {
     bind: function () {
 
         var compiler = this.compiler,
-            id = this.id = compiler.eval(this.expression)
+            id = this.expression
         if (!id) return
 
         var partial = id === 'yield'