Vuex: Does Vuex work with new Map(), as in key/value map lists?

Created on 3 Nov 2016  路  3Comments  路  Source: vuejs/vuex

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map

My state for a module looks like this:

const state = {
    loaded: false,
    items: new Map(),
}

I'm having some issues when updating an item in the list through a mutation, that it doesn't propagate through to the Vue component. In the component I have:

computed: {
    item() {
        return this.$store.state.module.items.get(this.pk)
    },
},

Am I using this wrong, or does Vuex not support Map()? If it's not supported, where would be a good place to put a load(pk) method?

Most helpful comment

Is there a way to use Map and Set with vue/vuex and some boilerplate, or is it just not supported at all?

All 3 comments

Hi, thanks for your interest in the project.

The problem is twofold:

  1. Vue reactivity system does not (yet) support Map, Set and their weak counterparts. There's a discussion on the topic: https://github.com/vuejs/vue/issues/2410
  2. Store data should be serializable, and there is no standard way to serialize Map and Set into JSON.

Is there a way to use Map and Set with vue/vuex and some boilerplate, or is it just not supported at all?

Was this page helpful?
0 / 5 - 0 ratings