I have an array of posts and each post has a user. I also have a select field where I can change the post's user. However only the user's id updates on the page and not the username itself. How could I have both of them update and reflect the change?
data() {
return {
posts: [
{
id: 1,
post_body: 'hello world',
user: {
id: 45,
username: 'Johnny13'
}
},
{
id: 2,
post_body: 'what is up?',
user: {
id: 97,
username: 'Billly75'
}
}
],
users: [
{id: 45, username: 'Johnny13'},
{id: 97, username: 'Billly75'}
]
}
}
html
<div v-for="(post, index) in posts">
The user for this post is:
{{ post.user.id }} <!-- this changes -->
{{ post.user.username }} <!-- this does not -->
Change the post's user:
<select v-model="post.user.id">
<option v-for="user in users" :value="user.id">{{ user.username }}</option>
</select>
</div>