0

I have Data in vuejs like following:

params: {
        comment: Object,
        state: "",
        deleteAppointment: false,
        appointmentId: null,
      }

I am filling data from two functions. First function is just assigning following lines:

  this.params.state = "BLACKLIST";
        this.params.deleteAppointment = true;
        this.params.appointmentId = this.appointmentId;

But, in the second function when I am assigning following:

   const comment = {};
      fd.forEach(function(value, key){
        comment[key] = value;
      });

      const data = {};
      Object.keys(this.lead).map((key) => {
        if (this.lead[key] != this.orginal[key]) {
          data[key] = this.lead[key];
        }
      });

      this.params = data; // May be the problem is here, data is overwriting existing properties of params
      this.params.comment = comment;

When assigning data in params, previous properties are vanishing! May be I need object copy or something! I couldn't understand what I have to do actually right now.

1 Answer 1

3

You should inherit the previous object using Spread Operator, try this

this.params = {...this.params, ...data};
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.