【发布时间】:2018-01-21 03:33:58
【问题描述】:
我正在使用 CryptoCompare API (https://www.cryptocompare.com/api/#-api-data-coinlist-),但在搜索时无法访问特定的硬币信息。相反,我返回的是整个硬币列表,而不是我搜索的那个。我猜这是我当时的陈述中的一个问题,但我不确定。这是我到目前为止的代码 - 问题区域在 searchImage 中
class SearchForm extends React.Component{
constructor(){
super();
this.state = {
currentSearch: "",
priceResults: [],
cryImage: [],
}
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
this.cryPrice = this.cryPrice.bind(this);
}
cryPrice(param){
axios.get(`https://min-api.cryptocompare.com/data/pricemulti?fsyms=${param}&tsyms=CAD`)
.then(res => {
const cryptos = res.data;
console.log(cryptos);
this.setState({
priceResults: cryptos
})
})
}
searchImage(param){
axios.get(`https://min-api.cryptocompare.com/data/all/coinlist`, {
params: {
name: `${param}`,
}
}).then(res => {
const cryImage = res.data;
console.log(cryImage);
this.setState({
cryImage
})
})
}
handleChange(e){
const currentSearchValue = e.target.value;
this.setState({
currentSearch: currentSearchValue
})
console.log(currentSearchValue);
}
handleSubmit(e){
e.preventDefault();
this.cryPrice(this.state.currentSearch);
this.searchImage(this.state.currentSearch);
this.setState({
currentSearch: ""
})
}
【问题讨论】:
标签: javascript reactjs get axios