好久没用axios调接口了,今天突然发现用get控制台打印不出参数,代码和控制台如下
用post方法就可以显示出来,后来查看了官方文档,发现代码少了params,添上就行了
this.axios.get('/TuNiu/getSearch', {
params: {
keyword: keyword,
}
}).then(response => {
console.log(response);
if (response.status === 200) {
this.locations = response.data.data.locations;
this.spots = response.data.data.spots;
} else{
}
console.log('城市推荐', response.data.data.locations);
console.log('景点推荐', response.data.data.spots);
}).catch(function (error) {
console.log(error);
});
官网例子如下