File tree 1 file changed +9
-7
lines changed
1 file changed +9
-7
lines changed Original file line number Diff line number Diff line change 13
13
Vue アプリケーションの情報源となっているのがリアクティブな ` data ` オブジェクト、すなわち、` data ` オブジェクトへのアクセスのみをプロキシするコンポーネントインスタンスであることは見過ごされがちです。それゆえに、複数のインスタンスで共有されるべき状態がある場合、オブジェクトをリアクティブにするために [ reactive] ( /guide/reactivity-fundamentals.html#declaring-reactive-state ) 関数を利用できます:
14
14
15
15
``` js
16
- const sourceOfTruth = Vue .reactive ({
16
+ const { createApp , reactive } = Vue
17
+
18
+ const sourceOfTruth = reactive ({
17
19
message: ' Hello'
18
20
})
19
21
20
- const appA = Vue . createApp ({
22
+ const appA = createApp ({
21
23
data () {
22
24
return sourceOfTruth
23
25
}
24
26
}).mount (' #app-a' )
25
27
26
- const appB = Vue . createApp ({
28
+ const appB = createApp ({
27
29
data () {
28
30
return sourceOfTruth
29
31
}
@@ -39,7 +41,7 @@ const appB = Vue.createApp({
39
41
このようにすることで ` sourceOfTruth ` が変化するたびに、` appA ` と ` appB ` の両方がそれぞれの view を自動的に更新します。いま、唯一の情報源を持っていることにはなりますが、デバッグは悪夢になるでしょう。あらゆるデータが、アプリケーションのどこからでも、そしていつでも、トレースを残すことなく変更できてしまうのです。
40
42
41
43
``` js
42
- const appB = Vue . createApp ({
44
+ const appB = createApp ({
43
45
data () {
44
46
return sourceOfTruth
45
47
},
@@ -55,7 +57,7 @@ const appB = Vue.createApp({
55
57
const store = {
56
58
debug: true ,
57
59
58
- state: Vue . reactive ({
60
+ state: reactive ({
59
61
message: ' Hello!'
60
62
}),
61
63
@@ -88,7 +90,7 @@ Store の状態を変化させる action がすべて store 自身の中にあ
88
90
```
89
91
90
92
``` js
91
- const appA = Vue . createApp ({
93
+ const appA = createApp ({
92
94
data () {
93
95
return {
94
96
privateState: {},
@@ -100,7 +102,7 @@ const appA = Vue.createApp({
100
102
}
101
103
}).mount (' #app-a' )
102
104
103
- const appB = Vue . createApp ({
105
+ const appB = createApp ({
104
106
data () {
105
107
return {
106
108
privateState: {},
You can’t perform that action at this time.
0 commit comments