回答編集履歴
2
vue2.xに書き換え
test
CHANGED
@@ -2,12 +2,10 @@
|
|
2
2
|
|
3
3
|
[responseType: 'text' return Json Object](https://github.com/axios/axios/issues/907)
|
4
4
|
|
5
|
-
|
5
|
+
あと、axiosをVueで使う場合は以下の書き方で問題ないはずです。
|
6
6
|
|
7
7
|
```vue
|
8
|
-
import {ref} from 'vue'
|
9
|
-
const resdata = ref([])
|
10
8
|
axios.get( 'data.json').then(function (response) {
|
11
|
-
|
9
|
+
console.log(response.data)
|
12
10
|
})
|
13
11
|
```
|
1
よく見たら書き方が古い
test
CHANGED
@@ -1,3 +1,13 @@
|
|
1
1
|
responseTypeを指定した場合はJSON化するので、それをオブジェクトに返すためにはJSON.Parseが必要なはずです。
|
2
2
|
|
3
3
|
[responseType: 'text' return Json Object](https://github.com/axios/axios/issues/907)
|
4
|
+
|
5
|
+
よく見たらVue3.2で記述していると見受けられるので、それだったら以下の書き方で問題ないはずです。これでresdataに紐づいた値を全部テンプレートに返してくれます。
|
6
|
+
|
7
|
+
```vue
|
8
|
+
import {ref} from 'vue'
|
9
|
+
const resdata = ref([])
|
10
|
+
axios.get( 'data.json').then(function (response) {
|
11
|
+
resdata.value = response.data
|
12
|
+
})
|
13
|
+
```
|