前提・実現したいこと
Nuxt.jsとRailsでサービスを作っています。削除リクエストの時だけthen
が実行されません。
DB上は期待通り削除されていますが、Nuxt側に記載しているthen
だけが実行されません。削除リクエスト以外の時は実行されます。
エラーはありません。
該当のソースコード
store/todo
js
1 delete ({ commit }, todo) { 2 this.$axios.$delete(url.POST_API + 'post_items/' + todo.id) 3 .then(() => { 4 commit('remove', todo) 5 commit('alertSwitchDelete', true, { root: true }) 6 setTimeout(() => { 7 commit('alertSwitchDelete', false, { root: true }) 8 }, 3000) 9 }) 10 .catch(() => { 11 commit('alertSwitchError', true, { root: true }) 12 setTimeout(() => { 13 commit('alertSwitchError', false, { root: true }) 14 }, 3000) 15 }) 16 } 17
store/index
js
1export const state = () => ({ 2 alertDelete: false, 3}) 4 5export const mutations = { 6 7 alertSwitchDelete (state, boolean) { 8 state.alertDelete = boolean 9 } 10 11}
Rails
controller
rb
1 2 def destroy 3 post = PostItem.find(params[:id]) 4 5 if post.destroy 6 render json: "ok", status: "ok" 7 else 8 render json: "error", status: "error" 9 end 10 end 11 12
試したこと
・誤字脱字を確認
・then内でconsole.log
をしてレスポンスを確認しましたが実行されませんでした。
あなたの回答
tips
プレビュー