1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Laravel、Vue.js】GETリクエストでパラメータを指定できない

Posted at

GETリクエストでaxiosのパラメータ指定をしようとしたが、パラメータを指定できなかった。

GETリクエスト
const response = await axios.get('/api/hoge', {
  // ここにパラメータを指定したいが、うまくいかない
  id: 12345
})

結論

getリクエストは第2引数にクエリパラメータをつけ、postリクエストは第2引数に送信するデータをつける。

GETリクエスト
const response = await axios.get('/api/hoge', {
  // ここに「params」というキー名でセットし、クエリパラメータを指定する
  params: {
    id: 12345
  }
})
POSTリクエスト
const response = await axios.post('/api/hoge', {
  id: 12345
})

POSTリクエストの場合は、HTML5のFormData APIを使用することもできる。

POSTリクエスト
const formData = new FormData()
formData.append('id', 12345)
const response = await axios.post('/api/hoge', formData)

参考

https://cloud6.net/so/laravel/272748
https://qiita.com/taroc/items/f22f7dd5d6d5443c72a4

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?