Skip to content

Commit 0626af6

Browse files
committed
v-bind: update v-model on same element when value bindings change
1 parent 7091255 commit 0626af6

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

src/directives/attr.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ module.exports = {
8686
var modelProp = modelProps[attr]
8787
if (modelProp) {
8888
this.el[modelProp] = value
89+
// update v-model if present
90+
var model = this.el.__v_model
91+
if (model) {
92+
model.listener()
93+
}
8994
}
9095
}
9196
}

src/directives/model/radio.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ module.exports = {
2727
return val
2828
}
2929

30-
this.on('change', function () {
30+
this.listener = function () {
3131
self.set(self.getValue())
32-
})
32+
}
33+
this.on('change', this.listener)
3334

3435
if (el.checked) {
3536
this._initValue = this.getValue()

src/directives/model/select.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,16 @@ module.exports = {
2727
this.multiple = el.hasAttribute('multiple')
2828

2929
// attach listener
30-
this.on('change', function () {
30+
this.listener = function () {
3131
var value = getValue(el, self.multiple)
3232
value = self.number
3333
? _.isArray(value)
3434
? value.map(_.toNumber)
3535
: _.toNumber(value)
3636
: value
3737
self.set(value)
38-
})
38+
}
39+
this.on('change', this.listener)
3940

4041
// check initial value (inline selected attribute)
4142
checkInitialValue.call(this)

0 commit comments

Comments
 (0)