This maybe?
<user-list :users="@json($users)" > </user-list>
Since you want an object or array, you don't need the single quotes for the prop.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi everyone, I am very new to vue.js and I don't know how to pass the variable correctly. So if there is tutorial showing correct ways, please kindly show me the link. Or if you are so generous, show me the way please.
I am using Vue.js and the concept is just like this: In my controller, i fetch some models, convert to json string and pass it to view, just like this.
$users = User::all();
$users->tojson();
return View('viewpath',compact('users'));
and in my view, I pass it to Vue componet and
<user-list :users="'{{$users}}'" > </user-list>
and on the component mounted event, I parse it and assign to the variable
props : ['users'],
data : function{
return {
user_list : { }
}
},
mounted ( ) {
this.user_list = JSON.parse(this.users);
},
Ugly. But everything is working fine ,but when there is single quote(') or double qoute("), JSON.parse() throws "invalid expression: Unexpected identifier" error.
Please or to participate in this conversation.