【发布时间】:2016-05-08 08:00:46
【问题描述】:
我在 Laravel 中使用 vue.js。
我有 3 张桌子。
Article
Location
article_location (pivot table)
如果我想将位置文章转换为 json,以便将其传递给 vue,我该怎么做?
<div class="container">
Location->article //all articles of a location to json
<template id="ln-data">
<ul>
<li v-for="value in list">
@{{ value.name }}
</li>
</ul>
</template>
<script>
Vue.config.debug = true;
Vue.component('data', {
template: '#ln-data',
props:['list'],
created() {
this.list = JSON.parse(this.list);
}
})
new Vue({
el: 'body'
});
</script>
我该怎么做?
编辑 --
控制器:
$location = location::all();
return view('locationproducts')->with('location',$location);
查看:
<div class="container">
<data list="{{ $location->article()->toJson() }}"></data>
</div>
位置模型:
public function article()
{
return $this->belongsToMany('App\article','article_location');
}
错误:
Macroable.php 第 81 行中的 ErrorException:方法文章没有 存在。 (看法: /home/vagrant/Code/project/resources/views/locationproducts.blade.php)
【问题讨论】:
标签: javascript php json laravel vue.js