0

I have a edit form in my application. When this component is created http request is sent and response data is saved in two different variables.

axios.get(this.initializeURL)
    .then((res) => {
        this.form = res.data.form
        this.formInit = res.data.form
    })

and "this.form" is binded with form inputs.

<input type="text" class="form-control" id="name" v-model="form.name">

My problem is : When the input fields are changed "this.formInit" object is also changed. but i haven't bind "this.formInit" with input fields.

Isn't the "this.formInit" supposed to contain the initial data from the response ?

Why is this unwanted binding happening ?

My goal is to compare "this.form" & "this.formInit" to check if the user changes some fields before tring to update the form.

1 Answer 1

1

You can create a new object using Object.assign:

axios.get(this.initializeURL)
    .then((res) => {
        this.form = Object.assign({}, res.data.form),
        this.formInit = res.data.form
    })
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.