3

I am facing an interesting problem: I have a form where I want to insert old values (if the form was submitted before) like this:

<input type="text" :value="oldName" id="name" />

Now the problem is that I can't overwrite the oldName variable like this, so yes, I have the old value in there, but I can't change it anymore. Can you think of a solution? I basically want the value to be in the textfield, but I want the user to be able to change it. Thank you!

1 Answer 1

5

Sounds like adding v-once to the input field would solve your problem. V-once means that oldName will be used to render the value once, but after that it will be a normal string literal.

<input type="text" :value="oldName" id="name" v-once/>

In case you want the user to be able to modify the value use v-model instead of v-bind. V-model provides two way binding so when the user writes something in the input field it is reflected in the value.

<input type="text" v-model="oldName" id="name" v-once/>
Sign up to request clarification or add additional context in comments.

3 Comments

cool idea and works for what I described initially. Thank you! However, this inputfield of mine has other values that have to be re-rendered. So what I am looking for would be to use v-once only for one attribute only, but that doesn't work.
@Hillcow modified the answer in case I misunderstood at first
oh, my question was so much more basic than I thought haha. Thank you!

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.