I’m trying to access email property of user object
{“name”:”test”, “email”:”test@test.x“}
like this:
<input type=”text” :placeholder=”user.email”>
When I try to access property in console -> console.log(user.email) everything work’s just fine
component code ->
<template>
<div>
<form method=”POST” action=”smth.php”>
<input type=”text” :placeholder=”user.email”>
</form>
</div>
</template>
<script>
export default {
props: {
user: {
type: Object,
required: true
}
},
}
</script>
Component call ->
<div class=”container”>
<page-profile :user=”{ $user->toJson() }”></page-profile>
</div>
Could you please show me the right way how to access the email property of user object?
Both console and npm watch show no errors.
Solution :
The issue is with this code:
<div class=”container”>
<page-profile :user=”{ $user->toJson() }”></page-profile>
</div>
You don’t need those curly braces in a property definition. Those are only required in the content of a tag and not an attribute.
I’m also not sure what the -> arrow is supposed to be doing. Is that from PHP?
You probably want something more like the following:
<div class=”container”>
<page-profile :user=”$user.toJson()”></page-profile>
</div>