0

I have this html code:

<div id="app">
    <input type="text" name="username" value="user.name">
</div>

With this Vue.js code:

new Vue({
    el: '#app',
    data: {
           user: {
                   name: 'John Doe',
                   age: 20
           },
           // etc...
    }
});

How can I show the Vue's data.user.name propertie's value in input filed?

If I try this:

<input type="text" name="username" v-model="user.name" value="user.name">

Then it says user is not defined

1 Answer 1

1

You can bind the value attribute using v-bind

<input type="text" name="username" v-bind:value="user.name">

Or using the shorthand of v-bind

    <input type="text" name="username" :value="user.name">

Or use a v-model

       <input type="text" name="username" v-model="user.name">

Here is the fiddle

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.