File tree Expand file tree Collapse file tree 1 file changed +9
-7
lines changed
Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Original file line number Diff line number Diff line change 1313Vue アプリケーションの情報源となっているのがリアクティブな ` data ` オブジェクト、すなわち、` data ` オブジェクトへのアクセスのみをプロキシするコンポーネントインスタンスであることは見過ごされがちです。それゆえに、複数のインスタンスで共有されるべき状態がある場合、オブジェクトをリアクティブにするために [ reactive] ( /guide/reactivity-fundamentals.html#declaring-reactive-state ) 関数を利用できます:
1414
1515``` js
16- const sourceOfTruth = Vue .reactive ({
16+ const { createApp , reactive } = Vue
17+
18+ const sourceOfTruth = reactive ({
1719 message: ' Hello'
1820})
1921
20- const appA = Vue . createApp ({
22+ const appA = createApp ({
2123 data () {
2224 return sourceOfTruth
2325 }
2426}).mount (' #app-a' )
2527
26- const appB = Vue . createApp ({
28+ const appB = createApp ({
2729 data () {
2830 return sourceOfTruth
2931 }
@@ -39,7 +41,7 @@ const appB = Vue.createApp({
3941このようにすることで ` sourceOfTruth ` が変化するたびに、` appA ` と ` appB ` の両方がそれぞれの view を自動的に更新します。いま、唯一の情報源を持っていることにはなりますが、デバッグは悪夢になるでしょう。あらゆるデータが、アプリケーションのどこからでも、そしていつでも、トレースを残すことなく変更できてしまうのです。
4042
4143``` js
42- const appB = Vue . createApp ({
44+ const appB = createApp ({
4345 data () {
4446 return sourceOfTruth
4547 },
@@ -55,7 +57,7 @@ const appB = Vue.createApp({
5557const store = {
5658 debug: true ,
5759
58- state: Vue . reactive ({
60+ state: reactive ({
5961 message: ' Hello!'
6062 }),
6163
@@ -88,7 +90,7 @@ Store の状態を変化させる action がすべて store 自身の中にあ
8890```
8991
9092``` js
91- const appA = Vue . createApp ({
93+ const appA = createApp ({
9294 data () {
9395 return {
9496 privateState: {},
@@ -100,7 +102,7 @@ const appA = Vue.createApp({
100102 }
101103}).mount (' #app-a' )
102104
103- const appB = Vue . createApp ({
105+ const appB = createApp ({
104106 data () {
105107 return {
106108 privateState: {},
You can’t perform that action at this time.
0 commit comments