forked from vuejs/vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckbox.js
42 lines (35 loc) · 861 Bytes
/
checkbox.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
var _ = require('../../util')
module.exports = {
bind: function () {
var self = this
var el = this.el
var trueExp = this._checkParam('true-exp')
var falseExp = this._checkParam('false-exp')
this._matchValue = function (value) {
if (trueExp !== null) {
return _.looseEqual(value, self.vm.$eval(trueExp))
} else {
return !!value
}
}
function getValue () {
var val = el.checked
if (val && trueExp !== null) {
val = self.vm.$eval(trueExp)
}
if (!val && falseExp !== null) {
val = self.vm.$eval(falseExp)
}
return val
}
this.on('change', function () {
self.set(getValue())
})
if (el.checked) {
this._initValue = getValue()
}
},
update: function (value) {
this.el.checked = this._matchValue(value)
}
}