0
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 5 years have passed since last update.

Nuxtでfetchした時、ローカルAPIが404になる

Posted at

404が帰ってくる

fetchでapiを叩き、ローカルの関数を実行しようとすると

entryList.vue
<script>
export default {
  fetch ({ store, params }) {
    store.dispatch('getEntries')
  }
}
</script>
store/index.js
<script>
export const actions = {
  getEntries({ commit }) {
    axios.get('/api/getEntries')
    .then((entries) => {
      commit('setEntries', entries)
    })
  }
}
</script>

みたいな感じになると思うのですが、404が帰ってくる。

原因

クライアントサイドとサーバーサイドでaxiosのbaseUrlを分けていなかったのが原因。
https://ja.nuxtjs.org/api/configuration-env/

答えはいつもドキュメント。

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