我正在使用ReactJS开发前端。
如何通过PHP(普通PHP或Yii1)提供此应用程序?
我想你想要通过HTTP协议来创建两者之间的通信。
在ReactJSX中,您希望进行从后端提供EndPoint / REST的提取/获取调用。
// at the beginning of your file
import axios from 'axios';
// in your component constructor
state = {
yourStateWithTheRecievedData: "",
}
// as a component method
componentDidMount = () => {
axios
.get('http://localhost:8080/YourBackendAPI')
.then(response => {
this.setState({
yourStateWithTheRecievedData: response.data.yourStateWithTheRecievedData
})
console.log(response.data.yourStateWithTheRecievedData)
})
}
您现在应该拥有一个包含您收到的数据的状态。如果您很难做到这一点,我建议您首先将其应用于公共API。您可以找到公共API的here列表