質問編集履歴
4
修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -16,8 +16,17 @@
|
|
16
16
|
```
|
17
17
|
|
18
18
|
というデータがあった際に、`{{ plan.title.rendered }}` でタイトルが出力されると思うのですが、
|
19
|
-
なぜか
|
19
|
+
なぜか 下記2つのエラーが出てしまいます。
|
20
20
|
|
21
|
+
`Uncaught TypeError: Cannot read property 'rendered' of undefined`
|
22
|
+
|
23
|
+
```
|
24
|
+
[Vue warn]: Unhandled error during execution of render function
|
25
|
+
at <Plan>
|
26
|
+
at <Simulation>
|
27
|
+
```
|
28
|
+
#####
|
29
|
+
|
21
30
|
ちなみに、`{{ plan.title }}` では、ちゃんと`"rendered": "タイトルタイトルタイトルタイトル"`と出力されます。
|
22
31
|
|
23
32
|
深い階層になった途端にエラーが発生してしまうのでなんでだろう?とはてな状態です。
|
3
修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -121,12 +121,6 @@
|
|
121
121
|
|
122
122
|
name : 'Plan',
|
123
123
|
|
124
|
-
data(){
|
125
|
-
return {
|
126
|
-
selectPlanData : []
|
127
|
-
}
|
128
|
-
},
|
129
|
-
|
130
124
|
created(){
|
131
125
|
this.fetchPlan({ id : 805 });
|
132
126
|
},
|
2
ソース修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -33,7 +33,7 @@
|
|
33
33
|
|
34
34
|
### ソースコード
|
35
35
|
```javascript
|
36
|
-
// store/index.
|
36
|
+
// store/index.js
|
37
37
|
|
38
38
|
import { createStore } from 'vuex'
|
39
39
|
import axios from 'axios'
|
1
ソースコード追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
例えば、
|
6
6
|
|
7
7
|
```
|
8
|
-
const
|
8
|
+
const plan = {
|
9
9
|
"id": 805,
|
10
10
|
"date": "2021-02-20T23:49:22",
|
11
11
|
"date_gmt": "2021-02-20T14:49:22",
|
@@ -15,10 +15,10 @@
|
|
15
15
|
}
|
16
16
|
```
|
17
17
|
|
18
|
-
というデータがあった際に、`{{
|
18
|
+
というデータがあった際に、`{{ plan.title.rendered }}` でタイトルが出力されると思うのですが、
|
19
19
|
なぜか `Uncaught TypeError: Cannot read property 'rendered' of undefined` とエラーが出てしまいます。
|
20
20
|
|
21
|
-
ちなみに、`{{
|
21
|
+
ちなみに、`{{ plan.title }}` では、ちゃんと`"rendered": "タイトルタイトルタイトルタイトル"`と出力されます。
|
22
22
|
|
23
23
|
深い階層になった途端にエラーが発生してしまうのでなんでだろう?とはてな状態です。
|
24
24
|
|
@@ -29,4 +29,116 @@
|
|
29
29
|
|
30
30
|
###環境
|
31
31
|
% vue --version
|
32
|
-
@vue/cli 5.0.0-beta.2
|
32
|
+
@vue/cli 5.0.0-beta.2
|
33
|
+
|
34
|
+
### ソースコード
|
35
|
+
```javascript
|
36
|
+
// store/index.html
|
37
|
+
|
38
|
+
import { createStore } from 'vuex'
|
39
|
+
import axios from 'axios'
|
40
|
+
|
41
|
+
export default createStore({
|
42
|
+
|
43
|
+
state : {
|
44
|
+
plan : ""
|
45
|
+
},
|
46
|
+
|
47
|
+
getters : {
|
48
|
+
plan : (state) => state.plan,
|
49
|
+
},
|
50
|
+
|
51
|
+
mutations : {
|
52
|
+
setPlan : (state, { plan }) => {
|
53
|
+
state.plan = plan
|
54
|
+
}
|
55
|
+
},
|
56
|
+
|
57
|
+
actions : {
|
58
|
+
|
59
|
+
async fetchPlan({ commit }, { id }){
|
60
|
+
|
61
|
+
const url = `https://localhost:8890/wp-json/wp/v2/posts/${id}/`;
|
62
|
+
|
63
|
+
const planRowData = await axios.get(url)
|
64
|
+
const plan = planRowData.data
|
65
|
+
|
66
|
+
if( !plan.id ) throw new Error('Invalid Post.')
|
67
|
+
|
68
|
+
commit('setPlan', { plan })
|
69
|
+
|
70
|
+
}
|
71
|
+
|
72
|
+
}
|
73
|
+
|
74
|
+
})
|
75
|
+
```
|
76
|
+
```
|
77
|
+
// App.vue
|
78
|
+
|
79
|
+
<template>
|
80
|
+
<div id="simulation" class="simulation">
|
81
|
+
|
82
|
+
<section>
|
83
|
+
|
84
|
+
<Plan/>
|
85
|
+
|
86
|
+
</section>
|
87
|
+
|
88
|
+
</div>
|
89
|
+
</template>
|
90
|
+
|
91
|
+
<script>
|
92
|
+
import Plan from './components/Plan'
|
93
|
+
|
94
|
+
export default {
|
95
|
+
|
96
|
+
name : 'Simulation',
|
97
|
+
|
98
|
+
components : {
|
99
|
+
Plan
|
100
|
+
}
|
101
|
+
|
102
|
+
}
|
103
|
+
</script>
|
104
|
+
```
|
105
|
+
```
|
106
|
+
|
107
|
+
// Plan.vue
|
108
|
+
<template>
|
109
|
+
<div>
|
110
|
+
|
111
|
+
{{ plan.title.rendered }}
|
112
|
+
// Uncaught TypeError: Cannot read property 'rendered' of undefined 発生!
|
113
|
+
|
114
|
+
</div>
|
115
|
+
</template>
|
116
|
+
|
117
|
+
<script>
|
118
|
+
import { mapGetters, mapActions } from "vuex";
|
119
|
+
|
120
|
+
export default {
|
121
|
+
|
122
|
+
name : 'Plan',
|
123
|
+
|
124
|
+
data(){
|
125
|
+
return {
|
126
|
+
selectPlanData : []
|
127
|
+
}
|
128
|
+
},
|
129
|
+
|
130
|
+
created(){
|
131
|
+
this.fetchPlan({ id : 805 });
|
132
|
+
},
|
133
|
+
|
134
|
+
computed : {
|
135
|
+
...mapGetters([ 'plan' ])
|
136
|
+
},
|
137
|
+
|
138
|
+
methods : {
|
139
|
+
...mapActions([ 'fetchPlan' ])
|
140
|
+
}
|
141
|
+
|
142
|
+
}
|
143
|
+
</script>
|
144
|
+
```
|