Vuex状态监听mapState与普通的局部计算属性混合使用

mapState如果和普通的局部计算属性混合使用,使用对象展开运算符(…)

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
data () {
return {
order: {
orderId: '',
amount: 0.0
}
}
},
computed: {
amount () {
return this.order.amount
},
...mapState({
order_create_watcher: state => state.order.order_create
order_confirm_watcher: state => state.order.order_confirm
})
},
watch: {
amount: 'amountWatcher',
order_create_watcher: {
handler: 'orderCreateWatcher',
deep: true
},
order_confirm_watcher: {
handler: 'orderConfirmWatcher',
deep: true
}
},
methods: {
amountWatcher (val, oldVal) {
...
},
orderCreateWatcher (val, oldVal) {
...
},
orderConfirmWatcher (val, oldVal) {
...
}
}

Powered by AppBlog.CN     浙ICP备14037229号

Copyright © 2012 - 2020 APP开发技术博客 All Rights Reserved.

访客数 : | 访问量 :