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.

v-snackbarをvuexに登録するとtimeout指定時にエラーになる

Posted at

エラーメッセージ

Error: [vuex] do not mutate vuex store state outside mutation handlers.

原因

timeoutを設定しているとshowフラグがタイムアウト時にFALSEに変更される。

しかし、vuexのmutationsもしくはactionsを呼び出して書き換えているわけではないので上記のようなエラーが発生する。

対策

v-snackbarの属性値
// タイムアウトの設定値を-1にする
timeout="-1"
actions
// スナックバー表示の後、非表示用のmutationを呼ぶ
export const actions = {
  setSnackbar( { commit }, snackbar) {
    commit('SET_SNACKBAR', snackbar)
    // スナックバーを設定したあとのsetTimeout関数で非表示用のmutationを呼ぶ
    setTimeout(() => {
      commit('CLEAR_SNACKBAR')
    }, 4000);
  },
  clearSnackbar( { commit } ) {
    commit('CLEAR_SNACKBAR')
  }
}

参考

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?