質問編集履歴
1
created部分のコードを追加しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -36,4 +36,23 @@
|
|
36
36
|
このコンポーネントが作成された際に、createdでaxiosを使いアイテムのデータ取得できています。
|
37
37
|
(画面上部には、アイテム名が表示される部分があり、そこにはクリックされたアイテム名が表示されています)
|
38
38
|
|
39
|
-
ご存知の方いましたら、よろしくお願いします。
|
39
|
+
ご存知の方いましたら、よろしくお願いします。
|
40
|
+
|
41
|
+
情報を追加させて頂きます。
|
42
|
+
```vue
|
43
|
+
created(){
|
44
|
+
this.fetchItem()
|
45
|
+
},
|
46
|
+
methods:{
|
47
|
+
fetchItem(){
|
48
|
+
const token = localStorage.getItem('token');
|
49
|
+
//JWT認証を使用しているためヘッダーにトークンをつけて送る必要があります
|
50
|
+
axios.get('/api/items/users/' + this.$store.state.user.id + '/' + this.$route.params.id, { headers: { Authorization: `Bearer ${token}` } })
|
51
|
+
.then(res => {
|
52
|
+
this.name = res.data.name //ここでnameにレスポンスデータがセットされます
|
53
|
+
})
|
54
|
+
.catch(err => {
|
55
|
+
this.message = err.data.statusText;
|
56
|
+
})
|
57
|
+
},
|
58
|
+
```
|