【发布时间】:2016-12-26 07:23:28
【问题描述】:
我正在使用 Laravel 5.3 进行开发。我也在使用分形。我也将 axios 作为 Http Client 来执行 Ajax 请求。
我正在使用 VueJS 2 将值解析为 html 视图。
ChairsController.php
public function index()
{
$chairs = Chair::paginate(25);
// Return a collection of $chair with pagination
return $this->response->withPaginator($chairs, new ChairTransformer());
}
app-vue.js
new Vue({
el: '#app',
data: {
chairs: []
},
mounted() {
axios.get('http://l5.app:8000/api/v1/chairs').then(response => this.chairs = response.data);
}
});
getchairs.blade.php
<div id="app">
<ul>
<li v-for="chair in chairs">{{ color }}</li>
</ul>
</div>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="https://unpkg.com/vue@2.1.6/dist/vue.js"></script>
<script src="js/app-vue.js"></script>
当我在浏览器中访问getchairs.blade.php时,出现错误:
2/2
ErrorException in c5c35433.php line 72:
Use of undefined constant color - assumed 'color' (View: /home/vagrant/sites/l5/resources/views/dev/getchairs.blade.php)
如何获取颜色值并根据记录总数进行迭代?任何帮助表示赞赏。
【问题讨论】:
标签: javascript php html mysql laravel