1

I am aiming to store key names of object I'm looping over with v-for in an array within my components data object. I have seen others pass it as props into a separate component, but I instead need to store it in the same component where I'm running my v-for loop.

<div v-for="(fieldData, fieldName, index) in fieldset.fields" :key="`c-form__field--${index + 1}`"></div>

I need to push each fieldName into an array called currentFields in my data object.

1 Answer 1

1

You can add a computed method to do that.

computed: {
    // a computed getter
    currentFields: 
      let arr = [];
      this.fieldset.forEach(fields => {
         arr.push(//whatever you need to save)
      });
      return arr;
    }
  }
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.