adonuxt-template
adonuxt-template copied to clipboard
Error raised when mutating a copy of an object inside a store getter
Version
Steps to reproduce
In my store, i've declared getters like this :
export const getters = {
foo(state) {
return (range) => {
const result = Object.assign({}, state.bar)
result[range].push('test') // raise an error
return result
}
}
When I call it in my component, I get a Vuex error : [vuex] do not mutate vuex store state outside mutation handlers
It only occurs when I'm mutating the array, if instead of doing a push i assign that property to a value (for example an integer):
result[range] = 1
It doesn't raise any error. Also, I can output the result of that getter without any problem, the array end with 'test' and the original array is not modified.
What is expected ?
Nothing, it shouldn't raise any error when I modify an array of a copy of an Object.
What is actually happening?
An error is raised when I add an element to an array of a copy of an Object.