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.

getとsetを使っているのにdo not mutate vuex store state outside mutation handlers.が出たとき解決策

Last updated at Posted at 2022-06-15

そもそもこのエラーの意味は?

ミューテーションハンドラーの外部でvuexストアの状態をミューテーションしないでください

状況

mapStateを使用していた訳でなく、computedにget,setを記載していた。
詳しくは下記のリンクに記載。

Vue.js:Vuexのエラー:「[vuex] Do not mutate vuex store state outside mutation handlers」の原因と対応例
しかし、エラーが起こる。

解決策

export default {
  props: {
    notCartItems: {
      type: Object,
      required: true,
    },
  },
  data() {
    return {
      items: JSON.parse(JSON.stringify(this.notCartItems)),
    }
  },
}
</script>

無理感が否めないので、もっと綺麗なコードを知っている方ご教授くださいmm
参考にさせて頂いたサイト
Vue.js:Vuexのエラー(vuex do not mutate vuex store outside mutation handlers)対策

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?