Skip to content

Commit 43fb9c9

Browse files
committed
fix vuejs#631 directive two-way set without update
1 parent 8a37764 commit 43fb9c9

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/directive.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,19 @@ p._bind = function (def) {
6262
if (this.bind) {
6363
this.bind()
6464
}
65-
if (
66-
this.update && this._watcherExp &&
67-
(!this.isLiteral || this._isDynamicLiteral) &&
68-
!this._checkStatement()
69-
) {
65+
if (this._watcherExp &&
66+
(this.update || this.twoWay) &&
67+
(!this.isLiteral || this._isDynamicLiteral) &&
68+
!this._checkStatement()) {
7069
// wrapped updater for context
7170
var dir = this
72-
var update = this._update = function (val, oldVal) {
73-
if (!dir._locked) {
74-
dir.update(val, oldVal)
75-
}
76-
}
71+
var update = this._update = this.update
72+
? function (val, oldVal) {
73+
if (!dir._locked) {
74+
dir.update(val, oldVal)
75+
}
76+
}
77+
: function () {} // noop if no update is provided
7778
// use raw expression as identifier because filters
7879
// make them different watchers
7980
var watcher = this.vm._watchers[this.raw]
@@ -97,7 +98,7 @@ p._bind = function (def) {
9798
this._watcher = watcher
9899
if (this._initValue != null) {
99100
watcher.set(this._initValue)
100-
} else {
101+
} else if (this.update) {
101102
this.update(watcher.value)
102103
}
103104
}

0 commit comments

Comments
 (0)