回答編集履歴

2

Vueでできるように

2019/11/12 01:23

投稿

mouse_484
mouse_484

スコア759

test CHANGED
File without changes

1

Vueでできるように

2019/11/12 01:23

投稿

mouse_484
mouse_484

スコア759

test CHANGED
@@ -1,5 +1,55 @@
1
- [async-data](https://ja.nuxtjs.org/guide/async-data)利用しくださ
1
+ async内では非同期処理をしたいときにawaitを使っそれを行ます
2
2
 
3
3
 
4
4
 
5
+ ```
6
+
7
+ new Vue({
8
+
9
+ data: {
10
+
11
+ shohinsArray: [],
12
+
5
- 非同期でdataを取得し、セットできます
13
+ termArr: [8, 9, 10],
14
+
15
+ },
16
+
17
+ methods: {
18
+
19
+ async query() {
20
+
21
+ for await (const thisterm of this.termArr) {
22
+
23
+ const resturl = `${inputResturl.value}/○○/?term=${thisterm}`;
24
+
25
+ axios.get(resturl).then((response) => {
26
+
27
+ this.shohinsArr.push({
28
+
29
+ item: response.data.item
30
+
31
+ });
32
+
33
+ });
34
+
35
+ }
36
+
37
+ return this.shohinsArr;
38
+
39
+ }
40
+
41
+ }
42
+
43
+ })
44
+
45
+ ```
46
+
47
+
48
+
49
+ 推奨されませんが簡単にするために await for-ofを使いました
50
+
51
+
52
+
53
+
54
+
55
+ ~~Nuxtと勘違いして回答したので編集しました~~