这是我的source code
问题实际上出在这些GET请求上
getModels = async () => {
if (this.state.query_brand !== 0) {
this.setState({ loading: "Fetching models..." });
let brand = Number(this.state.query_brand);
let targetURL =
'https://parallelum.com.br/fipe/api/v1/carros/marcas/${brand}' + '/modelos/';
await axios.get(`${targetURL}`)
.then(res => this.setState({ models: res.data }))
.catch(err => console.log(err));
}};
谢谢!!我用以下方法解决了这个问题:
let targetURL =
"https://parallelum.com.br/fipe/api/v1/carros/marcas/" +
brand +
"/modelos/" +
model +
"/anos";
console.log(targetURL);
await axios
.get(`${targetURL}`)...promises
答案 0 :(得分:0)
这里的问题:
let targetURL = 'https://parallelum.com.br/fipe/api/v1/carros/marcas/${brand}' + '/modelos/';
此行中的${brand}
是纯字符串,其值为= $ {brand} ,而不是brand
的值。您应该在此行中使用模板文字
let targetURL = `https://parallelum.com.br/fipe/api/v1/carros/marcas/${brand}/modelos/`;