私は別のサービス層にaxios
の機能の下に分離しようとしています。 Plsは反応するjsでこれを行う方法を提案しますか?反応するjs - How to doサービス層の呼び出し
```
class xxx extends Component {
constructor(props) {
super(props)
this.state = {
ownerName: '',
}
this.handleKeyUp = this.handleKeyUp.bind(this)
}
handleKeyUp(e) {
if (e.target.value.length > 4) {
var self = this
axios.get(`/https://exampleService.com/${e.target.value}`)
.then(function (response) {
self.setState({ownerName: response.data['name']})
})
.catch(function (error) {
if (error.response) {
if (error.response.status === 404) {
self.setState({ownerName: `\u2014`})
}
}
})
}
}
render() {
return (
<div>
<Input OnKeyUp={(event) => this.handleKeyUp(event)} ></Input>
</div>
);
}
}
```
私はmodule.exports
を使用して以下のように分離することを試みたが、私は、モジュール部品からの出力を取得し、XXXのコンポーネントにそれを渡すことができないんです。
ありがとう!それは偉大な働いた – user7700138