laravel - Axios 在 Laravel 的 Vue 组件访问数据时给出 undefined
问题描述
我正在使用 Laravel 和 Vue 的组件,当我尝试从 vue 组件中 axios 返回的响应中访问横幅属性时,它给了我未定义的信息。
我正在访问像response.data.banners
我通过以下方式从控制器返回数据:
public function getBanners(Request $request){
return response()->json(['
banners'=> BannerImage::active()->get()
]);
}
这是我访问 axios 响应的方式
<script>
export default {
data: function() {
return {
banners: []
}
},
mounted() {
axios.get("getBanners").then((res)=> {
console.log(res);
console.log(res.data);
console.log(res.data.banners);
this.banners = res.data.banners;
});
console.log('Component mounted.')
}
}
</script>
axios 的回应
在访问横幅属性之前一切正常。有什么我做的不对吗?
解决方案
推荐阅读
- .htaccess - .htaccess 多种情况的重写规则
- python - 机器人框架:从命令行使用 ${SPACE} 行为
- javascript - 从 React JS axios 发送请求时未提供身份验证凭据
- java - Android Array列表过滤器和分组具有相同键值的项目
- sql - 如何优化批量插入场景的触发器?
- javascript - 如何在同步函数中停止 JavaScript 中的函数?
- swift - 泛型类型在不透明类型的帮助下符合序列:一些 IteratorProtocol
- postman - 在 Postman 中用双引号替换单引号
- python - 是否可以从两个以上的 dns 服务器并行解析列表?
- c - vhdl 函数/过程常量参数