Explorar o código

fix #505 v-model initial value not piped through write filters

Evan You %!s(int64=11) %!d(string=hai) anos
pai
achega
a1c6bcd263

+ 5 - 1
src/directive.js

@@ -91,7 +91,11 @@ p._bind = function (def) {
       watcher.addCb(update)
     }
     this._watcher = watcher
-    this.update(watcher.value)
+    if (this._initValue != null) {
+      watcher.set(this._initValue)
+    } else {
+      this.update(watcher.value)
+    }
   }
   this._bound = true
 }

+ 1 - 2
src/directives/model/checkbox.js

@@ -10,8 +10,7 @@ module.exports = {
     }
     _.on(el, 'change', this.listener)
     if (el.checked) {
-      // watcher is not set up yet
-      this.vm.$set(this.expression, el.checked)
+      this._initValue = el.checked
     }
   },
 

+ 1 - 2
src/directives/model/radio.js

@@ -10,8 +10,7 @@ module.exports = {
     }
     _.on(el, 'change', this.listener)
     if (el.checked) {
-      // watcher is not set up yet
-      this.vm.$set(this.expression, el.value)
+      this._initValue = el.value
     }
   },
 

+ 1 - 1
src/directives/model/select.js

@@ -124,7 +124,7 @@ function checkInitialValue () {
     }
   }
   if (initValue) {
-    this.vm.$set(this.expression, initValue)
+    this._initValue = initValue
   }
 }
 

+ 1 - 2
src/directives/model/text.js

@@ -99,8 +99,7 @@ module.exports = {
       el.hasAttribute('value') ||
       (el.tagName === 'TEXTAREA' && el.value.trim())
     ) {
-      // watcher is not set up yet
-      this.vm.$set(this.expression, el.value)
+      this._initValue = el.value
     }
   },