0

I'm new in Vue and I try to set variable from Laravel controller to div using vuejs.

I've set variable in laravel controller and pass to the view on the following way:

$Category = Session::get('Category'); 
//I was previously set that session field and it's string 'category'

return view('index', compact('Category');

How i can read that variable in vuejs?

1 Answer 1

1

you can simply pass the stuff as property. If you component has a categories property

....
props: ['categories'],
...

And you use it like

<my-category-example-component :categories="json_encode($Category)"></my-category-example component>

Then you can access the information in your methods

methods: {
   test: function() { alert(this.categories); }
}

or in your template

<li v-for="category in categories">{{ cartegory }}</li>
1
  • Thank you dude, you saved me a lot of time.
    – Duka
    Commented May 3, 2017 at 10:10

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.