我有一个React组件,它是GaleryPage,我想显示一个信息列表,我发现它们的后端是file_name和Type_contract。这是我的后端代码:
app.post('/convert', upload.single('file'),(req, res) =>{
if(req.file){
let file= req.file.filename
let Type_contract = 'Contract'
let file_name = path.basename(file,path.extname(file))
console.log(file_name);
console.log(Type_contract);
}
res.redirect('/');
这是我的React组件:
import React, { Component } from 'react';
import 'bootstrap/dist/css/bootstrap.min.css';
class GaleryPage extends Component {
constructor(props) {
super(props);
this.state = {
file_name: '',
Type_contract:''
};
}
componentDidMount() {
const data = new FormData();
fetch('http://localhost:8080/upload',{
method: 'POST',
body: data
})
.then((file_name,Type_contract) => this.setState({
file_name: file_name,
Type_contract:Type_contract
})
)}
render() {
return (
<div>
<ul>
<li file_name={this.state.file_name}>file_name=
{this.state.file_name}</li>
<li Type_contract={this.state.Type_contract}>Type_contract=
{this.state.Type_contract}</li>
</ul>
</div>
);
}
}
export default GaleryPage;
当我尝试这个代码时,我总是找到空白页面而没有显示数据