[Vuejs]-How to pass data from component to the store Vue?

0👍

methods: { // my component
  ...mapMutations(['setContactListName']), //import function from  the store
  viewHandler(id, item) { // hadler
    this.$router.push(`/company/sample-contact/${id}`);
    this.setContactListName(item); // pass data to the function
  }
}

or using this.$store.commit

methods: { // my component
  viewHandler(id, item) { // hadler
    this.$router.push(`/company/sample-contact/${id}`);
    this.$store.commit('setContactListName', item);
  }
}

Leave a comment