下面是将值从子组件传递到reactjs中的父组件的正确示例.
App.jsx
import React from 'react';
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
data: 'Initial data...'
}
this.updateState = this.updateState.bind(this);
};
updateState() {
this.setState({data: 'Data updated from the child component...'})
}
render() {
return (
<div>
<Content myDataProp = {this.state.data}
updateStateProp = {this.updateState}></Content>
</div>
);
}
}
class Content extends React.Component {
render() {
return (
<div>
<button onClick = {this.props.updateStateProp}>CLICK</button>
<h3>{this.props.myDataProp}</h3>
</div>
);
}
}
export default App;
Run Code Online (Sandbox Code Playgroud)
main.js
import React from 'react';
import ReactDOM …Run Code Online (Sandbox Code Playgroud) 在用户登录他的帐户后,我在烧瓶(python 框架)中使用用户的电子邮件 ID创建了一个会话。好的,它的工作正常,并且在我交叉检查时创建了会话。它的网址是. 但是,当用户从浏览器单击注销按钮时,我发现会话不起作用..(我不知道,虽然我在登录时创建了会话)。"http://localhost:5000/login"
我的 ajax 代码在apache2 服务器上以"http://localhost:80/index.html".
当我使用curl交叉检查时,它工作正常。但是,在浏览器的情况下,当我单击注销按钮时,我在终端(ubuntu)上发现了一条消息,表明您的会话已过期,这是我在登录时创建的。
在这里,Ajax代码为登录的一部分的index.html
// Login ajax python
$("#btn_login").click(function(){
var txt1 = $("#txt1").val();
var txt3 = $("#txt3").val();
console.log("text: ", txt1, txt3);
var a = {"username": txt1, "password": txt3, "type": "login"};
$.ajax(
{
url: "http://localhost:5000/login",
type: "POST",
headers: {"Content-Type": "application/json"},
data: JSON.stringify(a),
dataType: "json",
success: function(response) { …Run Code Online (Sandbox Code Playgroud)