質問編集履歴
2
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
Nuxt.jsで
|
1
|
+
Nuxt.jsでコンポーネント間のデータのやり取りについて
|
test
CHANGED
File without changes
|
1
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,8 +1,28 @@
|
|
1
|
-
フォームで入力した値をヘッダー側で参照したいのですが、
|
1
|
+
フォームで入力した値をヘッダー側で参照したいのですが、上手く値が取れません。
|
2
|
+
|
3
|
+
|
4
|
+
|
2
|
-
|
5
|
+
ログアウト時に入力中のデータをDBに登録するため、ヘッダー内にあるログアウトボタンを押下時にフォームのデータを参照、受け取る必要があります。
|
6
|
+
|
7
|
+
|
8
|
+
|
3
|
-
|
9
|
+
どうぞご教授お願いいたします。
|
10
|
+
|
11
|
+
|
12
|
+
|
4
|
-
|
13
|
+
### 試したこと
|
14
|
+
|
5
|
-
|
15
|
+
propsを利用したりして、コンポーネント間のデータのやり取りを試したが書き方が悪いのかダメでした。
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
フロント開発が初めてでさらにvue.js、nuxt.jsも使うのが初めてで、すでにあるソースに変更を加える形になります。
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
どうぞご教授よろしくお願いいたします。
|
6
26
|
|
7
27
|
|
8
28
|
|
@@ -10,50 +30,570 @@
|
|
10
30
|
|
11
31
|
|
12
32
|
|
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
|
-
se
|
33
|
+
### 構成
|
34
|
+
|
35
|
+
```
|
36
|
+
|
37
|
+
index.vue(indexからheade、form、footerをimport)
|
38
|
+
|
39
|
+
header.vue
|
40
|
+
|
41
|
+
form.vue(formからinput、inputshort、selectをimport)
|
42
|
+
|
43
|
+
input.vue
|
44
|
+
|
45
|
+
select.vue
|
46
|
+
|
47
|
+
footer.vue
|
48
|
+
|
49
|
+
```
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
### index.vue
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
```
|
58
|
+
|
59
|
+
<template>
|
60
|
+
|
61
|
+
<section class="Container">
|
62
|
+
|
63
|
+
<div class="App">
|
64
|
+
|
65
|
+
<Header :text="title" v-if="!isApp" v-model="postDT"></Header>
|
66
|
+
|
67
|
+
<div>
|
68
|
+
|
69
|
+
<Form v-model="postDT"></Form>
|
70
|
+
|
71
|
+
<PageTop></PageTop>
|
72
|
+
|
73
|
+
<Footer v-if="!isApp"></Footer>
|
74
|
+
|
75
|
+
</div>
|
76
|
+
|
77
|
+
</div>
|
78
|
+
|
79
|
+
</section>
|
80
|
+
|
81
|
+
</template>
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
<script>
|
86
|
+
|
87
|
+
import Header from "@/components/AAAAA/Header";
|
88
|
+
|
89
|
+
import Form from "@/components/AAAAA/Form";
|
90
|
+
|
91
|
+
import PageTop from "@/components/AAAAA/PageTop";
|
92
|
+
|
93
|
+
import Footer from "@/components/AAAAA/Footer";
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
import Meta from "~/assets/mixins/metaDT";
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
export default {
|
102
|
+
|
103
|
+
mixins: [Meta],
|
104
|
+
|
105
|
+
components: {
|
106
|
+
|
107
|
+
Header,
|
108
|
+
|
109
|
+
Form,
|
110
|
+
|
111
|
+
PageTop,
|
112
|
+
|
113
|
+
Footer
|
114
|
+
|
115
|
+
},
|
116
|
+
|
117
|
+
data() {
|
118
|
+
|
119
|
+
return {
|
120
|
+
|
121
|
+
title: "",
|
122
|
+
|
123
|
+
meta: {
|
124
|
+
|
125
|
+
title: "",
|
126
|
+
|
127
|
+
description: ""
|
128
|
+
|
129
|
+
},
|
130
|
+
|
131
|
+
postDT: {}
|
132
|
+
|
133
|
+
};
|
134
|
+
|
135
|
+
},
|
136
|
+
|
137
|
+
asyncData({ store, route, userAgent }) {
|
138
|
+
|
139
|
+
let isApp = false;
|
140
|
+
|
141
|
+
if (userAgent.indexOf("") > -1) {
|
142
|
+
|
143
|
+
isApp = true;
|
144
|
+
|
145
|
+
} else {
|
146
|
+
|
147
|
+
isApp = false;
|
148
|
+
|
149
|
+
}
|
150
|
+
|
151
|
+
return {
|
152
|
+
|
153
|
+
isApp
|
154
|
+
|
155
|
+
};
|
156
|
+
|
157
|
+
}
|
158
|
+
|
159
|
+
};
|
160
|
+
|
161
|
+
```
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
### header
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
```
|
170
|
+
|
171
|
+
<template>
|
172
|
+
|
173
|
+
<header class="Header" :class="XXXXX">
|
174
|
+
|
175
|
+
<div class="Header-inner">
|
176
|
+
|
177
|
+
<p class="Header-logo">
|
178
|
+
|
179
|
+
<img src="*.svg" alt="XXXX" />
|
180
|
+
|
181
|
+
</p>
|
182
|
+
|
183
|
+
<span class="Text">{{text}}</span>
|
184
|
+
|
185
|
+
<button class="Header-logout" @click="handleLogout">ログアウト</button>
|
186
|
+
|
187
|
+
</div>
|
188
|
+
|
189
|
+
</header>
|
190
|
+
|
191
|
+
</template>
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
<script>
|
196
|
+
|
197
|
+
export default {
|
198
|
+
|
199
|
+
props: ["text", "postDT"],
|
200
|
+
|
201
|
+
data() {
|
202
|
+
|
203
|
+
return {
|
204
|
+
|
205
|
+
cookieParams: ""
|
206
|
+
|
207
|
+
};
|
208
|
+
|
209
|
+
},
|
210
|
+
|
211
|
+
methods: {
|
212
|
+
|
213
|
+
handleLogout() {
|
214
|
+
|
215
|
+
if (window.confirm("ログアウトしてもよろしいですか?")) {
|
216
|
+
|
217
|
+
const cookies = document.cookie.split(";");
|
218
|
+
|
219
|
+
const result = cookies.filter(x => x.indexOf("__xxxParams") > -1);
|
220
|
+
|
221
|
+
if (result[0]) {
|
222
|
+
|
223
|
+
this.cookieParams = result[0].split("=")[1];
|
224
|
+
|
225
|
+
}
|
226
|
+
|
227
|
+
this.$store.commit("XXXXX", true);
|
228
|
+
|
229
|
+
この辺りでformのデータを取得する。
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
this.$axios
|
234
|
+
|
235
|
+
.post(
|
236
|
+
|
237
|
+
`${this.$store.state.XXXXXXXXXX}/xxxxxLogout/`,
|
238
|
+
|
239
|
+
{
|
240
|
+
|
241
|
+
url: this.cookieParams,
|
242
|
+
|
243
|
+
input_data: {
|
244
|
+
|
245
|
+
ここにフォームで入力したデータをセットする
|
246
|
+
|
247
|
+
}
|
248
|
+
|
249
|
+
},
|
250
|
+
|
251
|
+
{
|
252
|
+
|
253
|
+
headers: {
|
254
|
+
|
255
|
+
accept: "application/json",
|
256
|
+
|
257
|
+
"Content-Type": "application/json",
|
258
|
+
|
259
|
+
token: this.$store.state.sessionId
|
260
|
+
|
261
|
+
}
|
262
|
+
|
263
|
+
}
|
264
|
+
|
265
|
+
)
|
266
|
+
|
267
|
+
.then(res => {
|
268
|
+
|
269
|
+
this.$store.commit("XXXXX", false);
|
270
|
+
|
271
|
+
this.$router.push(`/xxxxx/?p=${this.cookieParams}`);
|
272
|
+
|
273
|
+
})
|
274
|
+
|
275
|
+
.catch(err => {
|
276
|
+
|
277
|
+
this.$store.commit("XXXXX", false);
|
278
|
+
|
279
|
+
this.$router.push(`/xxxxx/?p=${this.cookieParams}`);
|
280
|
+
|
281
|
+
});
|
282
|
+
|
283
|
+
} else {
|
284
|
+
|
285
|
+
return;
|
286
|
+
|
287
|
+
}
|
288
|
+
|
289
|
+
}
|
290
|
+
|
291
|
+
}
|
292
|
+
|
293
|
+
};
|
294
|
+
|
295
|
+
</script>
|
296
|
+
|
297
|
+
```
|
298
|
+
|
299
|
+
|
300
|
+
|
301
|
+
### Form.vue
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
```
|
306
|
+
|
307
|
+
<template>
|
308
|
+
|
309
|
+
<div class="Form">
|
310
|
+
|
311
|
+
<div class="Form-wrap" v-show="!$store.state.postFlg">
|
312
|
+
|
313
|
+
<section-heading headingName="セクションタイトル"></section-heading>
|
314
|
+
|
315
|
+
<div class="Form-inner">
|
316
|
+
|
317
|
+
<div class="Form-content">
|
318
|
+
|
319
|
+
<FormLabel labelName="GGGGG" isRequired="true"></FormLabel>
|
320
|
+
|
321
|
+
<div class="Select-wrap">
|
322
|
+
|
323
|
+
<select-boxA
|
324
|
+
|
325
|
+
ID="GGGGG"
|
326
|
+
|
327
|
+
labelRequire="true"
|
328
|
+
|
329
|
+
@xxxxx-code="xxxxx"
|
330
|
+
|
331
|
+
v-model="postDT.corporateGenre">
|
332
|
+
|
333
|
+
</select-boxA>
|
334
|
+
|
335
|
+
</div>
|
336
|
+
|
337
|
+
</div>
|
338
|
+
|
339
|
+
<div class="Form-content">
|
340
|
+
|
341
|
+
<FormLabel labelName="YYYYY" isRequired="true"></FormLabel>
|
342
|
+
|
343
|
+
<div class="Select-wrap">
|
344
|
+
|
345
|
+
<selec-boxB
|
346
|
+
|
347
|
+
ID="HHHHH"
|
348
|
+
|
349
|
+
labelRequire="true"
|
350
|
+
|
351
|
+
@FFFFF-code="FFFFF"
|
352
|
+
|
353
|
+
</select-boxB>
|
354
|
+
|
355
|
+
</div>
|
356
|
+
|
357
|
+
</div>
|
358
|
+
|
359
|
+
<div class="Form-content">
|
360
|
+
|
361
|
+
<FormLabel labelName="ID" isRequired="true"></FormLabel>
|
362
|
+
|
363
|
+
<input-field
|
364
|
+
|
365
|
+
ID="id"
|
366
|
+
|
367
|
+
labelRequire="true"
|
368
|
+
|
369
|
+
class="is-short"
|
370
|
+
|
371
|
+
textFiledType="number"
|
372
|
+
|
373
|
+
textFiledSize="default"
|
374
|
+
|
375
|
+
maxLength=8
|
376
|
+
|
377
|
+
v-model="postDT.id">
|
378
|
+
|
379
|
+
</input-field>
|
380
|
+
|
381
|
+
</div>
|
382
|
+
|
383
|
+
<div class="Form-content">
|
384
|
+
|
385
|
+
<FormLabel labelName="名称" isRequired="true"></FormLabel>
|
386
|
+
|
387
|
+
<input-field
|
388
|
+
|
389
|
+
ID="name"
|
390
|
+
|
391
|
+
labelRequire="true"
|
392
|
+
|
393
|
+
class="is-short"
|
394
|
+
|
395
|
+
textFiledType="text"
|
396
|
+
|
397
|
+
textFiledSize="default"
|
398
|
+
|
399
|
+
maxLength=8
|
400
|
+
|
401
|
+
v-model="postDT.name">
|
402
|
+
|
403
|
+
</input-field>
|
404
|
+
|
405
|
+
</div>
|
406
|
+
|
407
|
+
</div>
|
408
|
+
|
409
|
+
</div>
|
410
|
+
|
411
|
+
</div>
|
412
|
+
|
413
|
+
</template>
|
414
|
+
|
415
|
+
|
416
|
+
|
417
|
+
```
|
418
|
+
|
419
|
+
|
420
|
+
|
421
|
+
|
422
|
+
|
423
|
+
|
424
|
+
|
425
|
+
|
426
|
+
|
427
|
+
|
428
|
+
|
429
|
+
### selectA
|
430
|
+
|
431
|
+
|
432
|
+
|
433
|
+
```
|
434
|
+
|
435
|
+
<template>
|
436
|
+
|
437
|
+
<div class="Selectbox" :class="{isError: confirmError}">
|
438
|
+
|
439
|
+
<select :id="ID" :class="{isSelected: selected}" v-model="selected" @change="handleSelected">
|
440
|
+
|
441
|
+
<option disabled value>選択してください</option>
|
442
|
+
|
443
|
+
<option
|
444
|
+
|
445
|
+
v-for="xxxxx in xxxxxs"
|
446
|
+
|
447
|
+
:key="xxxxx.code"
|
448
|
+
|
449
|
+
:value="`${xxxxx.name}`"
|
450
|
+
|
451
|
+
>{{xxxxx.name}}</option>
|
452
|
+
|
453
|
+
</select>
|
454
|
+
|
455
|
+
</div>
|
456
|
+
|
457
|
+
</template>
|
458
|
+
|
459
|
+
|
460
|
+
|
461
|
+
<script>
|
462
|
+
|
463
|
+
import { xxx } from "~/assets/data/xxx.json";
|
464
|
+
|
465
|
+
|
466
|
+
|
467
|
+
export default {
|
468
|
+
|
469
|
+
props: ["ID", "value", "confirmError"],
|
470
|
+
|
471
|
+
data() {
|
472
|
+
|
473
|
+
return {
|
474
|
+
|
475
|
+
selected: "",
|
476
|
+
|
477
|
+
prefectures
|
478
|
+
|
479
|
+
};
|
480
|
+
|
481
|
+
},
|
482
|
+
|
483
|
+
methods: {
|
484
|
+
|
485
|
+
handleSelected() {
|
486
|
+
|
487
|
+
this.$emit("input", this.selected);
|
488
|
+
|
489
|
+
this.xxxxxCode();
|
490
|
+
|
491
|
+
},
|
492
|
+
|
493
|
+
xxxxxCode() {
|
494
|
+
|
495
|
+
const xxxxx = this.xxxxx.filter(
|
496
|
+
|
497
|
+
xxxxx => xxxxx.name === this.selected
|
498
|
+
|
499
|
+
);
|
500
|
+
|
501
|
+
this.$emit("xxx-code", xxx);
|
502
|
+
|
503
|
+
}
|
504
|
+
|
505
|
+
},
|
506
|
+
|
507
|
+
mounted() {
|
508
|
+
|
509
|
+
setTimeout(() => {
|
510
|
+
|
511
|
+
this.selected = this.$props.value;
|
512
|
+
|
513
|
+
this.xxxxxCode();
|
514
|
+
|
515
|
+
}, 1500);
|
516
|
+
|
517
|
+
}
|
518
|
+
|
519
|
+
};
|
520
|
+
|
521
|
+
</script>
|
522
|
+
|
523
|
+
```
|
524
|
+
|
525
|
+
|
526
|
+
|
527
|
+
### inputbox.vue
|
528
|
+
|
529
|
+
|
530
|
+
|
531
|
+
```
|
532
|
+
|
533
|
+
<template>
|
534
|
+
|
535
|
+
<div class="FormItem" :class="textFiledSize">
|
536
|
+
|
537
|
+
<FormLabel v-if="labelTitle" :labelName="labelTitle" :isRequired="labelRequire"></FormLabel>
|
538
|
+
|
539
|
+
<input
|
540
|
+
|
541
|
+
:id="ID"
|
542
|
+
|
543
|
+
class="TextField"
|
544
|
+
|
545
|
+
:value="value"
|
546
|
+
|
547
|
+
type="text"
|
548
|
+
|
549
|
+
pattern="\d*"
|
550
|
+
|
551
|
+
:maxlength=maxLength
|
552
|
+
|
553
|
+
v-on:input="$emit('input', $event.target.value)">
|
554
|
+
|
555
|
+
</div>
|
556
|
+
|
557
|
+
</template>
|
558
|
+
|
559
|
+
|
560
|
+
|
561
|
+
<script>
|
562
|
+
|
563
|
+
import FormLabel from '@/components/XXXXX/FormLabel'
|
564
|
+
|
565
|
+
|
566
|
+
|
567
|
+
export default {
|
568
|
+
|
569
|
+
props: ['ID','labelTitle', 'labelRequire', 'textFiledType', 'placeholderText', 'textFiledSize', 'value', 'confirmError' ,'noneMessege' , 'maxLength', 'min'],
|
570
|
+
|
571
|
+
components: {
|
572
|
+
|
573
|
+
FormLabel
|
574
|
+
|
575
|
+
},
|
576
|
+
|
577
|
+
computed: {
|
578
|
+
|
579
|
+
textExist() {
|
580
|
+
|
581
|
+
return this.$props.value.length
|
582
|
+
|
583
|
+
},
|
584
|
+
|
585
|
+
textSize() {
|
586
|
+
|
587
|
+
return this.$props.textFiledSize
|
588
|
+
|
589
|
+
}
|
590
|
+
|
591
|
+
}
|
592
|
+
|
593
|
+
}
|
594
|
+
|
595
|
+
</script>
|
596
|
+
|
597
|
+
|
598
|
+
|
599
|
+
```
|