Evan You 12 лет назад
Родитель
Сommit
9c4b62fd50
2 измененных файлов с 11 добавлено и 10 удалено
  1. 5 5
      src/compiler.js
  2. 6 5
      src/directive-parser.js

+ 5 - 5
src/compiler.js

@@ -294,17 +294,17 @@ CompilerProto.bindDirective = function (directive) {
         }
     }
 
+    var value = binding.value
     // invoke bind hook if exists
     if (directive.bind) {
-        directive.bind(binding.value)
+        directive.bind(value)
     }
 
     // set initial value
-    if (binding.value) {
-        directive.update(binding.value)
-    }
     if (binding.isComputed) {
-        directive.refresh()
+        directive.refresh(value)
+    } else {
+        directive.update(value)
     }
 }
 

+ 6 - 5
src/directive-parser.js

@@ -56,8 +56,8 @@ var DirProto = Directive.prototype
  *  for computed properties, this will only be called once
  *  during initialization.
  */
-DirProto.update = function (value) {
-    if (value && (value === this.value)) return
+DirProto.update = function (value, init) {
+    if (!init && value === this.value) return
     this.value = value
     this.apply(value)
 }
@@ -66,14 +66,15 @@ DirProto.update = function (value) {
  *  -- computed property only --
  *  called when a dependency has changed
  */
-DirProto.refresh = function () {
+DirProto.refresh = function (value) {
     // pass element and viewmodel info to the getter
     // enables powerful context-aware bindings
-    var value = this.value.get({
+    if (value) this.value = value
+    value = this.value.get({
         el: this.el,
         vm: this.vm
     })
-    if (value === this.computedValue) return
+    if (value && value === this.computedValue) return
     this.computedValue = value
     this.apply(value)
     this.binding.pub()