1

I have an array and a map in the parent components.
By using a button, I update the value of both of them.
I expected both value will be updated automatically once the prop value changed, but only the array was being updated.
How can I listen to the update of the Map in the child components?

// Parent Component
<template>
  <div>   
    <ChildComponent :map-data.sync="mapData" :array-data.sync="arrayData"></ChildComponent>
    <br>
    <b-button variant="outline-primary" v-on:click.prevent="updateData">update data</b-button>
  </div>

</template>

<script>
  export default {
    name: "Parent-Component",
    components: {
      ChildComponent
    },
    data() {
      return {
        mapData: new Map(),
        arrayData: []
      }
    },
    created() {
      this.mapData.set("A", 0);
    },
    methods: {
      updateData() {
        this.mapData.set("A", this.mapData.get("A") + 1);
        this.arrayData.push("newData");
      }
    }
  };
</script>


// Child component script
<script>
  export default {
    name: "Child-Component",
    props:['arrayData', 'mapData'],
    components: {
    },
    watch: {
      mapData: function () {
        console.log("this is never called");
      },
      arrayData: function() {
        console.log("this is called as expected");
      }
    }
  };
</script>

1 Answer 1

1

Map reactivity, IMK, is still not supported in Vue. You can find detailed explanation (and a possible workaround) to this here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.