File Structure
Inside App.blade.php
I used vue router to pull the components.
I have a normal variable like $users which I can access in blade file like {{$users}} . Now how can I access the same data in my component?
If your $users variable is a collection you can use:
<my-component :users="{!! $users->toJson() !!}"></my-component>
.php file.App.blade.php is mentioned.Laravel is php server side scripting language which compiled before front end Javascript and Vue is javascript.
So to get value of php variable in js take this value in a input text field as json
<input type="hidden" id="users" value="{{json_encode($users)}}">
And inside vuejs inside mount() update your data's, users element
mounted(){
var users = document.querySelector("#users").value;
users = JSON.pars(users);
this.users = users;
}
For this purpose I am using props, Look at my example :
I have a QuestionComponent and I want to sent $quetion_set->id valuable to the file so that In blade file I sent a props ,
<question question_set_id="{{$question_set->id}}"/>
In the QuestionComponent I set props : props:['question_set_id'], then used it in the component like this : this.question_set_id
If you want to pass array data then you should use JSON.parse function to reache your data , for example :
JSON.parse(this.question_set_id)['id']
.phpfile or in.jsor.vuefile ?