-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTest.vue
86 lines (73 loc) · 1.93 KB
/
Test.vue
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<template>
<div class="">
left : {{left}}px<br>
top : {{top}}px<br>
<button @click="window_open = ! window_open">切换窗口组件</button>
<br>
<button @click="setTopLeft">修改全局状态</button>
<br>
<button @click="resetTopLeft">覆盖全局状态</button>
<window v-if="window_open"></window>
</div>
</template>
<script>
import { mapState } from 'vuex'
import { setStoreModule, resetStoreModule } from './index.js'
import window from './components/window.vue'
export default {
state : [ 'left', 'top' ],
components : {
window,
},
data () {
return {
window_open : false,
}
},
computed : {
...mapState( {
top : s => s.base.top,
left : s => s.base.left,
} )
},
mounted () {
this.$store.commit( 'top', 50 );
this.$store.commit( 'left', 50 );
},
methods : {
setTopLeft() {
var statusMeta = {
right : {
module : "base",
},
bottom : {
module : "base",
}
}
setStoreModule( this.$store, statusMeta )
// 调用设置状态后原状态依然存在
this.$store.commit( 'left', 10 );
this.$store.commit( 'top', 10 );
},
resetTopLeft () {
var statusMeta = {
right : {
module : "base",
},
bottom : {
module : "base",
}
}
resetStoreModule( this.$store, statusMeta )
// 调用覆盖状态后left与top被清除
try {
this.$store.commit( 'left', 10 );
this.$store.commit( 'top', 10 );
} catch ( e ) {
}
}
}
}
</script>
<style>
</style>