作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在使用 Laravel 5.3 进行开发。我也在使用分形。我还将 axios 作为 Http 客户端来执行 Ajax 请求。
如果我发送获取请求以显示所有椅子 api。我返回时显示如下:
我正在使用 VueJS 2 将值解析为 html View 。
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)
如何获取颜色值并根据记录总数进行迭代?感谢您的帮助。
最佳答案
由于 laravel blade 模板引擎也使用花括号,你必须使用 @
来转义它,就像这样 @{{ color }}
。这样 blade 就会忽略它,不会尝试在 vuejs 之前进行评估。这不仅适用于 blade/vuejs 的情况,也适用于 blade/angular。阅读"Blade & JavaScript Frameworks"文档部分。
关于javascript - 如何使用 Vue JS 遍历数组的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41327812/
我是一名优秀的程序员,十分优秀!