<template>
<p id="login">
<p>
用户: <input type="text" v-model="username" :value='info.name'>
密码: <input type ="text" v-model="password" :value='info.psd'>
</p>
</p>
</template>
<script>
export default{
name:'login',
data(){
return{
username:'',
password:'',
info:{
name:'123',
psd:'123',
},
}
},
}
</script>
I want the input to initially display the value in info, and then I can use the value of v-model, but the effect cannot be achieved. The value of info is not displayed. Is it wrong to write this way? How should I write to achieve my needs?
It’s two-way anyway, why bother adding more.
It is recommended to remove v-bind:value and write info.name and info.psd directly to v-model. The code is as follows:
When the value of the input changes, the username and password also change
v-model is the syntax sugar for v-bind:input and v-bind:value.
Solved, just use an input and a p
https://jsfiddle.net/stardew/...