简体   繁体   English

来自 Axios 的响应数据将我的 JSON 转换为 Object ZA8CFDE6331BD59EB6666F89111C4

[英]response data from Axios converts my JSON in an Object object

I'm trying to make a request from the backend using Axios, this is the data that is requested我正在尝试使用 Axios 从后端发出请求,这是请求的数据

[
    {
        "_id": "5ed99cd7972ceb1e203ff3d4",
        "model": "76 Runer Nylonmedieval Blue-grey Violet ",
        "code": "352077-14",
        "brand": "PUMA",
        "description": "Corres mucho",
        "value": 119000,
        "size": 11,
        "stock": 50,
        "date": "2020-06-05T01:14:17.000Z",
        "image": "upload\\352077-14.jpg",
        "total": 714000
    },
    {
        "_id": "5edc01f0efed972e1c13c76e",
        "model": "Force",
        "code": "200-1142",
        "brand": "Reebok",
        "description": "Perfectos para realizar crossfit, con dos agarres laterales perfectos para Rope Climbing",
        "value": 310000,
        "size": 45,
        "stock": 20,
        "date": "2020-06-06T20:50:44.000Z",
        "image": "upload\\Screenshot_8.png",
        "total": 1240000
    },
    {
        "_id": "5edc0163efed972e1c13c76c",
        "model": "Elegant",
        "code": "2002-1",
        "brand": "Velez",
        "description": "comodos y perfectos para ocasiones especiales ",
        "value": 340000,
        "size": 41,
        "stock": 13,
        "date": "2020-06-06T20:48:26.000Z",
        "image": "upload\\Screenshot_1.png",
        "total": 680000
    }
]

But when I try to console.log it in my page I just get as a response "data [object Object],[object Object],[object Object]" so I can't use any of the json data.但是当我尝试在我的页面中 console.log 时,我只是得到一个响应“数据 [对象对象],[对象对象],[对象对象]”,所以我不能使用任何 json 数据。 This is the axios request in the frontend:这是前端的 axios 请求:

axios.get('http://localhost:5000/users/carProducts/'+ID.userid)
            .then(res =>{
                console.log('data '+res.data)
            })
            .catch(error => console.log(error));

You are getting the data perfectly.您正在完美地获取数据。 the thing is you are logging it wrong .问题是您记录错误

When you concatenate string with object, output looks like this data [object Object],[object Object],[object Object]当您将字符串与 object 连接时,output 看起来像这样的data [object Object],[object Object],[object Object]

Try passing data as param.尝试将数据作为参数传递。 You will see the data你会看到数据

 console.log('data ',res.data)

 let data={'name':'trevor'} console.log("Details"+data) console.log("Difference") console.log("Details",data)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM