Skip to content
This repository has been archived by the owner on Feb 2, 2021. It is now read-only.

Error raised when mutating a copy of an object inside a store getter #128

Open
VoKhuong opened this issue Aug 2, 2020 · 0 comments
Open

Comments

@VoKhuong
Copy link

VoKhuong commented Aug 2, 2020

Version

2.13

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.

This bug report is available on Nuxt community (#c109)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant