0

I need to add a value (position) to my vuejs form data on submit.

 data() {
   return {
     position: "Assistant",
      form: {
       firstname: null,
       lastname: null,
     },
   };
 }

I tried the following on submit but it doesn't work:

Method

  onSubmit() {    
    this.form.push({
            position: this.position,
        })
  }

How do I append this value to data object?

1
  • 1
    form is an object. you can not use push. The push() method adds one or more elements to the end of an array Commented Dec 9, 2020 at 12:33

1 Answer 1

2

Push works with an array, not with an object.

form is an object. So, you can add a property in these ways:

this.form.position = this.position;

this.form['position'] = this.position;
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.