0
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.

バリデーション のためにステータスコードを取得する

Last updated at Posted at 2021-02-19

#概要
ステータスコードが422の場合、バリデーションをフロントに表示したかったので、ステータスコードの取得方法をまとめました。

#解決

.vue
<script>
export default {
  methods: {
    async submit(){
      await axios.post('/api/account', formData).then(res=>{
        console.log(res.status) 
      }).catch(err => {
        console.log(err.response.status) 
      })
    },
  },
}
</script>

ステータスコード

200の場合:res.status,
エラーの場合:err.response.status

0
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
0
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?