1
1

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.

axiosを利用してVue.jsからサーバーサイドにFormDataを送る方法

Posted at

vuejsからサーバーサイドへFormDataを送る方法を備忘録として載せます.

方法

axiosはデフォルトではjson形式としてリクエストを送信する.
そのためFormDataとしてリクエストを送るためには, 以下のように FormData オブジェクトを作成, インスタンス化した後, append() メソッドで送りたい値を付与する.

const params = new FormData()
params.append( key, value );

具体例

v-model='mailAddress'
v-model='password'
import axios from 'axios'

const params = new FormData();
params.append('mailAdress', this.mailAddress);
params.append('password', this.password);

axios.post(
   ' URL ',
    params,
   { headers: {'Content-Type':'application/json'} } //Content-Typeを記述
)
.then(response => {
   ...
});

このようにすることでサーバーサイドにFormDataとして送ることができる.

参考文献

1
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?