我正在调用API并传入一些动态变量。调用api时,所有动态变量都会以正确的方式进行评估和保存,但 ownerName 被调用。以下是我的功能:
_onPressRegister() {
const { latitude, longitude } = this.props;
const { city, phone, country } = this.state;
const ownerName = `${this.state.firstName} `${this.state.lastName}`';
axios.post('http://sewoa-easy-breezy-home-number-api-us1.smx.online/api/v1/houses/registration', { house: { owner_name: ownerName,
latitude: latitude,
longitude: longitude,
telephone: phone,
city: city,
location_summary: '',
country: country
} }).then((response) => {
console.log(response);
if (response.data.number) {
Actions.viewHouseNumber({ houseNumber: response.data.number });
}
})
.catch((error) => {
if (error.response) {
// The request was made, but the server responded with a status code
// that falls out of the range of 2xx
this.setState({ error: error.response.data });
console.log(error.response.data);
console.log(error.response.status);
console.log(error.response.headers);
} else {
// Something happened in setting up the request that triggered an Error
console.log('Error', error.message);
this.setState({ error: error.message });
}
console.log(error.config);
});
}
当 api 执行帖子时,不会评估 owner_name 。相反,它在数据库中保存的方式与它的编写方式完全相同。
`${this.state.firstName} `${this.state.lastName}`'
我一直在苦苦挣扎。任何人都可以帮助我。 PS:此外,当我尝试使用“+”符号进行简单连接时,api调用不会通过。 非常感谢你的帮助。