Skip to content

Getting mutation error in Nuxt JS while binding form with state

I am trying to bind my form’s fields with my vuex store in Nuxt JS. It works fine with normal text fields with get() set() in computed. But having trouble in customizing getting and setting manually. I am trying to push objects to an array in a specific format from my template to store and also keep the binding among them. Here is my code:

  <div class="container setting-form-area-business">
    <b-form-group v-for="(input, index) in phoneNumbers" :key="`phoneInput-${index}`">
      <label>Mobile Number {{index+1}}*</label>
        <b-form-input v-model="" @input="updateStore" class="custom-form-input-business">
        <b-input-group-append v-show="phoneNumbers.length > 1">
          <b-button class="mobile-number-remove-btn" @click="removeField(index, phoneNumbers)"></b-button>




      <b-button class="jh-btn2" @click="addField">Add More Mobile Number</b-button>


  export default {
    props: [

    data() {
      return {
        phoneNumbers: this.$ ? this.$
          .mobileNumber : [{
            phone: ""

    computed: {
      mobilenumbers() {
        return this.$

    methods: {

      addField() {
          value: ""

      removeField(index, fieldType) {

        fieldType.splice(index, 1);
        console.log('fieldType', fieldType);
      updateStore() {
        this.$store.commit('business/setformmobileNumber', {
          mobileNumber: this.phoneNumbers


this was working fine when I was in vue, but coming to nuxt, it is giving me error

[vuex] do not mutate vuex store state outside mutation handlers.



As told by the error, you should not mutate the state. There are several ways to handle this one. A quick search here could give you a lot of answers.

This is mine (using Lodash’s cloneDeep):

User contributions licensed under: CC BY-SA
9 People found this is helpful