我是Vue的新手,我尝试使用vuejs从Laravel控制器设置变量到div。
我在laravel控制器中设置了变量,并按以下方式传递到视图:
$Category = Session::get('Category');
//I was previously set that session field and it's string 'category'
return view('index', compact('Category');
我怎么能用vuejs读取那个变量?
发布于 2017-04-29 09:27:45
您可以简单地将这些东西作为属性传递。如果组件具有类别属性
....
props: ['categories'],
...
你用它就像
<my-category-example-component :categories="json_encode($Category)"></my-category-example component>
然后,您可以访问方法中的信息。
methods: {
test: function() { alert(this.categories); }
}
或者在你的模板中
<li v-for="category in categories">{{ cartegory }}</li>
https://stackoverflow.com/questions/43688911
复制相似问题