-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwith.js
47 lines (42 loc) · 922 Bytes
/
with.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
43
44
45
46
47
var _ = require('../util')
var Watcher = require('../watcher')
module.exports = {
priority: 900,
bind: function () {
var vm = this.vm
if (this.el !== vm.$el) {
_.warn(
'v-with can only be used on instance root elements.'
)
} else if (!vm.$parent) {
_.warn(
'v-with must be used on an instance with a parent.'
)
} else {
var key = this.arg
this.watcher = new Watcher(
vm.$parent,
this.expression,
key
? function (val) {
vm.$set(key, val)
}
: function (val) {
vm.$data = val
}
)
// initial set
var initialVal = this.watcher.value
if (key) {
vm.$set(key, initialVal)
} else {
vm.$data = initialVal
}
}
},
unbind: function () {
if (this.watcher) {
this.watcher.teardown()
}
}
}