如何从MySQL DB渲染(反应)图像?

时间:2019-08-07 01:29:09

标签: javascript mysql reactjs

我已经成功地发布了图像文件名并将其取回,但仍停留在如何在可及范围ImageGallery组件(源于其中)中进行渲染

      this.state = {
      isOpen: false,
      images: [],
      files: ""
    }
}

onSubmit = (e) => {
  e.preventDefault()
  var data = {
      images: document.imgAdd.file.value
  }
  console.log("Submit was clicked", data);
fetch("/gallery/images", {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify(data)
}).then(function(response) {
  if (response.status >= 400) {
    throw new Error("Bad response from server");
  }
  return response.json();
}).then(function(data) {
  console.log(data);    

}).catch(function(err) {
  console.log(err)
});
}

componentDidMount() {
  let url = "/gallery/images"
  fetch(url, {
      method: 'GET'
  }).then(function(response) {
      if (response.status >= 400) {
          throw new Error("Bad response from server");
      }
      return response.json();
  }).then(images => {
      this.setState({images:images});
      console.log(images)
  }).catch(err => {
  console.log('caught it!',err);
  })
}




      render() {

        return (

        <div className="addImg">
           <form className="imgAdditon" name="imgAdd" method="POST" onSubmit={this.onSubmit}>


我没有收到任何错误消息,但是看不到页面上显示的图像

0 个答案:

没有答案