teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

vueファイルのタイポを修正しました

2021/09/11 10:06

投稿

dietono
dietono

スコア10

title CHANGED
File without changes
body CHANGED
@@ -110,8 +110,8 @@
110
110
  #### App.vue
111
111
  ```
112
112
  <template>
113
- <p>{{ user }}</p>
113
+ <p>{{ userState.user.age }}</p>
114
- <p>{{ product }}</p>
114
+ <p>{{ productState.product.price }}</p>
115
115
  </template>
116
116
 
117
117
  <script lang="ts">
@@ -131,8 +131,8 @@
131
131
  console.log(productState.product.price);
132
132
 
133
133
  return {
134
- user: userState,
134
+ userState,
135
- product: productState,
135
+ productState,
136
136
  };
137
137
  },
138
138
  });

1

stateの構成が間違っていましたので修正しました。

2021/09/11 10:06

投稿

dietono
dietono

スコア10

title CHANGED
File without changes
body CHANGED
@@ -16,60 +16,56 @@
16
16
  ```typescript
17
17
  import { reactive } from "vue";
18
18
 
19
- interface user {
19
+ interface userStateType {
20
+ user: {
20
- id: number;
21
+ id: number;
21
- name: string;
22
+ name: string;
23
+ age: number;
24
+ };
22
25
  }
23
26
 
24
- interface userState {
25
- user: user[];
26
- }
27
-
28
27
  export const userState = () => {
29
28
  const state = reactive({
30
- user: [
29
+ user: {
31
- {
32
- id: 1,
30
+ id: 1,
33
- name: "Taro",
31
+ name: "Taro",
32
+ age: 18,
34
- },
33
+ },
35
- ],
36
- }) as userState;
34
+ }) as userStateType;
37
35
 
38
36
  return {
39
37
  state,
40
38
  };
41
39
  };
40
+
42
41
  ```
43
42
 
44
43
  #### store/product.ts
45
44
  ```typescript
46
45
  import { reactive } from "vue";
47
46
 
48
- interface product {
47
+ interface productStateType {
48
+ product: {
49
- id: number;
49
+ id: number;
50
- name: string;
50
+ name: string;
51
- price: number;
51
+ price: number;
52
+ };
52
53
  }
53
54
 
54
- interface productState {
55
- product: product[];
56
- }
57
-
58
55
  export const productState = () => {
59
56
  const state = reactive({
60
- product: [
57
+ product: {
61
- {
62
- id: 1,
58
+ id: 1,
63
- name: "car",
59
+ name: "car",
64
- price: 1000,
60
+ price: 1000,
65
- },
61
+ },
66
- ],
67
- }) as productState;
62
+ }) as productStateType;
68
63
 
69
64
  return {
70
65
  state,
71
66
  };
72
67
  };
68
+
73
69
  ```
74
70
 
75
71
  #### store/index.ts
@@ -131,8 +127,8 @@
131
127
  // エラー
132
128
  // TS2339: Property 'id' does not exist on type 'state | state'.
133
129
  // Property 'id' does not exist on type 'state'.
134
- console.log(userState.id);
130
+ console.log(userState.user.age);
135
- console.log(productState.id);
131
+ console.log(productState.product.price);
136
132
 
137
133
  return {
138
134
  user: userState,