LoginSignup
0
0

More than 1 year has passed since last update.

外部API呼び出し時にaxiosでCORSエラー

Last updated at Posted at 2023-05-20

外部APIを利用しようとしたところCORSエラーが起きた。

エラーが起きる悪いパターン

error_pattern.vue
<script>
export default {
  async asyncData(context){
    const response = await context.$axios.$get('外部APIのURL')
    console.log(response.data)
    return { getData: response.data }
  }
}
</script>

良いパターン

ok_pattern.vue
<script>
import axios from 'axios'
export default {
  async asyncData(){
    const response = await axios.get('外部APIのURL')
    console.log(response.data)
    return { getData: response.data }
  }
}
</script>
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