In my store module, I am encountering an issue with the following pseudo-code:
const state = {
users: []
}
const actions = {
addUsers: async ({commit, state}, payload) => {
let users = state.users // <-- problem
// fetching new users
for(let i of newUsersThatGotFetched) {
users.push('user1') // <-- really slow
}
commit('setUsers',users)
}
}
const mutations = {
setUsers: (state, { users }) => {
Vue.set(state, 'users', users)
}
}
Upon running this code, I am getting the error message
Error: [vuex] Do not mutate vuex store state outside mutation handlers
.
Disabling strict mode resolves the error, but results in a significant decrease in performance. It seems like the errors are occurring without being displayed.
The issue appears to be at the point where I commented // <-- problem
. However, when I modify that line to
let users = []
everything functions smoothly. Unfortunately, I require the data from state.users and cannot proceed with an empty array.