js踩坑|打印接口数据返回[object Object]

373 阅读1分钟

原代码如下:

        api.getSwiperBanner()
        .then(res=>{
            console.log('Swiper----'+ res.data);
            this.banner=res.data;
        })
    },

控制台输出如下信息:

image.png

排查后发现,

 console.log('Swiper----'+ res.data);

该语句中,出现字符串和对象相加,对象调用toSting()方法隐式转换成字符串。

修正方法:

        api.getSwiperBanner()
        .then(res=>{
            console.log('Swiper----', res.data);//将加号改为逗号
            this.banner=res.data;
        })
    },

修正后控制台输出:

image.png

完美解决!