HTTP status

2023-7-13 Less than 1 minute

Hit F12 to access Developer Tools and view the console logs.

# Mock data file

/**
 * @url https://www.api.com/status404
 * @method get
 * @status 404
 */
module.exports = 'Not Found'

# Vue code

<template>
  <div class="demo">
    <button @click="get">GET https://www.api.com/status404</button>
    <div class="result"> {{ msg }} </div>
    <div class="tips">Hit F12 to access Developer Tools and view the console logs.</div>
  </div>
</template>

<script>
import axios from 'axios';
export default {
  data() {
    return { msg: '' }
  },
  methods: {
    get() {
      axios.get('https://www.api.com/status404').catch(err => {
        this.msg = err.message; // Request failed with status code 404
      });
    },
  }
}
</script>
<style scoped src="./demo.css">

Note

axios will throw an error when meets a 404 response.

Last update: July 13, 2023 22:53