Skip to content

Commit a1c6bcd

Browse files
committed
fix #505 v-model initial value not piped through write filters
1 parent 21c011e commit a1c6bcd

File tree

5 files changed

+9
-8
lines changed

5 files changed

+9
-8
lines changed

src/directive.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,11 @@ p._bind = function (def) {
9191
watcher.addCb(update)
9292
}
9393
this._watcher = watcher
94-
this.update(watcher.value)
94+
if (this._initValue != null) {
95+
watcher.set(this._initValue)
96+
} else {
97+
this.update(watcher.value)
98+
}
9599
}
96100
this._bound = true
97101
}

src/directives/model/checkbox.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ module.exports = {
1010
}
1111
_.on(el, 'change', this.listener)
1212
if (el.checked) {
13-
// watcher is not set up yet
14-
this.vm.$set(this.expression, el.checked)
13+
this._initValue = el.checked
1514
}
1615
},
1716

src/directives/model/radio.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ module.exports = {
1010
}
1111
_.on(el, 'change', this.listener)
1212
if (el.checked) {
13-
// watcher is not set up yet
14-
this.vm.$set(this.expression, el.value)
13+
this._initValue = el.value
1514
}
1615
},
1716

src/directives/model/select.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ function checkInitialValue () {
124124
}
125125
}
126126
if (initValue) {
127-
this.vm.$set(this.expression, initValue)
127+
this._initValue = initValue
128128
}
129129
}
130130

src/directives/model/text.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ module.exports = {
9999
el.hasAttribute('value') ||
100100
(el.tagName === 'TEXTAREA' && el.value.trim())
101101
) {
102-
// watcher is not set up yet
103-
this.vm.$set(this.expression, el.value)
102+
this._initValue = el.value
104103
}
105104
},
106105

0 commit comments

Comments
 (0)