每次提交区域时,它都会显示此错误:
'未捕获的错误:引发了跨源错误。React 无权访问开发中的实际错误对象”
它仅在我按下提交区域按钮时发生,我猜当旧状态更改为新状态时会发生这种情况。 (this.setState)
创建区域.js
import React, { Component } from "react";
export default class CreateZone extends Component {
constructor(props) {
super(props);
this.state = {
zone: {
name: "",
zipCode: "",
},
};
}
updateZone(event) {
let updated = Object.assign({}, this.state.zone);
updated[event.target.id] = event.target.value;
this.setState({
zone: updated,
});
}
submitZone(event) {
console.log("SubmitZone: " + JSON.stringify(this.state.zone));
this.props.onCreate(this.state.zone);
}
render() {
return (
<div>
<input
onChange={this.updateZone.bind(this)}
className="form-control"
id="name"
type="text"
placeholder="Name"
/>{" "}
<br />
<input
onChange={this.updateZone.bind(this)}
className="form-control"
id="zipCode"
type="text"
placeholder="Zip Code" …Run Code Online (Sandbox Code Playgroud) 如何在反应中反转数组?我尝试使用 this.state.data.maps.reverse 但它不起作用。提前致谢!
import React, { Component } from 'react';
export default class Slideshows extends Component {
constructor(){
super();
this.state = {
data:[
{ "id": "1", "name": 'Robert', "age": "21" },
{ "id": "2", "name": 'Sam', "age": "33" },
{ "id": "3", "name": 'Jerry', "age": "42" },
]
}
}
render() {
const reverseData = this.state.map((data, i) => {
return (
<li> {data.name} | {data.age} </li>
)
})
return (
<ul>
{reverseData}
</ul>
)
}
}
Run Code Online (Sandbox Code Playgroud) 我正在使用一个名为checkType的函数来检查用户是否输入了整数类型的有效输入。例如,如果用户输入 15 它将打印valid, 15c 将打印not valid。但是,如果用户只输入像ccccc这样的字符串 input ,则会导致无限循环并且程序崩溃。我在下面添加了一些屏幕截图来显示输出。
int checkType(int input, char *c) {
if (input == 2 and *c == '\n') {
return 1;
} else {
return 0;
};
}
int main(void) {
int faces = 0;
char c;
int valid = 0;
int input;
while (valid == 0) {
printf("Enter number of faces: ");
input = scanf("%d%c", &faces, &c);
valid = checkType(input, &c);
printf(valid == 0 ? "not valid\n" …Run Code Online (Sandbox Code Playgroud) 你能解释一下这条线是什么吗?props 和 {...props} 有什么作用?
<Route exact path='/' render={props => <Home {...props} />} />
Run Code Online (Sandbox Code Playgroud) javascript ×3
reactjs ×3
node.js ×2
c ×1
mern ×1
react-redux ×1
react-router ×1
scanf ×1
superagent ×1