T
T
Timofey Mikhailov2020-04-30 18:55:05
Vue.js
Timofey Mikhailov, 2020-04-30 18:55:05

Vuex, problem with "strict: true" totalitarian mode?

I will give part of the code

<div class="row" v-for="(book, index) in this.books" :key="index">
    <input class="name-book" v-model="book.title">
  </div>

Now, if you write code like this, an error constantly pops up
"Error: [vuex] do not mutate vuex store state outside mutation handlers."

When I want to edit this input .

As I understand it, he doesn’t like that I directly change the data in state , and that’s why he swears.
For this I write the following:
<input class="name-book" v-model="inputBook">
  ...
  ...
  computed: {
    inputBook: {
      get(){},
      set(){},
    }
  }
  ...

And then I understand that I don’t know how to pass the index to inputBook,
I write like this: It doesn’t give anything =( Tell me, please ...
get(...arg){ console.log(...arg); },

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Gololobov, 2020-04-30
@dGololobov

<div class="row" v-for="(book, index) in books" :key="index">
    <input class="name-book" v-model="books[index]title">
  </div>

The v-model should not be accessing the deterministic array books
. But the error seems to be "Error: [vuex] do not mutate vuex store state outside mutation handlers." it won't solve it.
to write a value to the store, you need to use actions and mutations

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question