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 1 year has passed since last update.

Javasrcript リクエストメソッドがGETの時,配列のデータをURLパラメータに渡したい

Last updated at Posted at 2022-08-13
  • HTTPリクエスト GETだと、URLパラメータに配列のデータを付与できるの?
  • できなかったら HTTPリクエスト POSTで送らないといけない...?
    という不安を解消します

結論 : URLパラメータに配列のデータを付与できる

1つの手段 : qsライブラリを仕様することで解決

import * as qs from 'qs'
import axios from 'axios'

const addData = async () => {
    // a=bとなってパラメータ付与する
    // { a: ['b','c'] }とすれば良い
    const data = await axios.get(`http://localhost:3000/test?${qs.stringify({ a: 'b' })}`)

    return data
}

1
0
1

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?