axios get 方法vue 可以获取json 数据但不能获取其属性

时间:2020-12-30 21:52:23

标签: php json vue.js axios

我想在 vue 应用程序中从我的数据库中获取数据。请求是使用 axios 发出的。我将数据作为一个整体对象获取,但是一旦我尝试访问某个属性,应用程序就会响应它是未定义的。我的猜测是,数据并未真正转换为 JSON 格式,因此无法访问属性。我已经尝试过 JSON.parse() 但它不起作用。

I console logged the the data access 第一个控制台输出是整个对象,第二个输出应该是一个特定的属性

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));

process.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;
}

?>

有人看到这里的问题吗?

0 个答案:

没有答案
相关问题