LoginSignup
0
0

More than 3 years have passed since last update.

[vuex] do not mutate vuex store state outside mutation handlers. 対策

Posted at

やりたいこと

  • 原因
  • 対策

いってみよう!

原因

テキストボックスにvuexの内容を入れたら起きるようです。

<template>
  <v-text-field
    v-model='user["id"]'
  ></v-text-field>
</template>

<script>
    export default {
        data: () => ({
            user: {}
        }),
        mounted() {
            this.user = this.$store.getters['user']
        }
    }
</script>

この状態で、テキストボックスの内容を変更すると、
[vuex] do not mutate vuex store state outside mutation handlers.
になります。

対策

this.user = {
              id: this.$store.getters['user']["id"],
              name: this.$store.getters['user']["name"],
            }

ちゃんとキーまで入れると上記のエラーが解消されます。
直接 this.$store.getters['user'] を入れるのがダメで、考えてみればオブジェクトをそのまま入れてるのでvuexの内容を書きかえてしまっていますね。

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