php - axios get方法vue可以获取json数据但不能获取其属性
问题描述
我想在 vue 应用程序中从我的数据库中获取数据。正在使用 axios 发出请求。我将数据作为一个整体对象获取,但是一旦我尝试达到某个属性,应用程序就会响应它是未定义的。我的猜测是,数据并没有真正转换为 JSON 格式,因此无法访问属性。我已经尝试过 JSON.parse() 但它不起作用。
我控制台记录了数据访问 第一个控制台输出是整个对象,第二个输出应该是一个特定的属性
Index.html(进行 axios 调用的地方)
methods: {
getAllBooks(){
axios.get("url").then(
function(response) {
if(response.data.error) {
app.errorMsg = JSON.parse(response.data.message);
} else{
app.buecher = response.data;
console.log(typeof app.buecher);
console.log(JSON.stringify(app.buecher)); //if I remove stringify here it logs [object object]
console.log(JSON.stringify(app.buecher.ProduktID));
进程.php
$response = array();
while ($zeile = mysqli_fetch_assoc($db_erg))
{
$response[] = $zeile;
}
echo json_encode($response); // as far as I understood $response is JSON from that moment on
mysqli_free_result( $db_erg );
exit;
}
?>
有人看到这里的问题吗?
解决方案
推荐阅读
- node.js - 使用 Node.js 查询连接两个 Postgres 数据库表
- c++ - unique_ptr 和 shared_ptr 的重载方法与多态性不明确
- ssl - ionic 应用服务器设置的 https 设置
- angular - 如何将 dx-data-grid 及其工具包装到另一个组件中并使其成为控制器?
- java - java.text.ParseException - 格式正确
- delphi - Delphi 远程调试器无法通过 WAN 连接工作
- database - wix 安装程序工具集中的 ComboBox 上的自定义操作删除/添加
- android - 一段时间后,AsyncTask 在服务中变慢
- python - 如何从多列中返回一个分组列的平均值
- sabre - 创建乘客姓名记录 - 消息 NO FARE FOR CLASS USED