作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 ReactJS 的初学者。需要知道如何将一个页面中的 props 值发送到另一个页面。 Prop 位于第一页上我可以获取类组件值如何获取另一页中的值。提前致谢
wallcolor.jsx
import React, { Component } from "react";
import { SketchPicker } from 'react-color';
import WallFactory from "../../wall-factory-3d";
export default class WallColor extends Component {
constructor(props) {
super(props);
this.state = {
background: '#d3d3d3',
};
}
handleChangeComplete(e){
this.setState({ background: e.hex },()=>{
return <WallFactory background={this.state.background}/>
});
};
render() {
return (
<SketchPicker color={ this.state.background } onChangeComplete={(e)=>this.handleChangeComplete(e)} />
);
}
}
另一个页面是wall-factory-3d.js
import { handleChangeComplete } from "../../components/toolbar/wallcolor";
import * as SharedStyle from '../../shared-style';
function get_color(props){
console.log(props.background);
}
我尝试了这个但没有得到输出。
最佳答案
意见,但这是我会做的......:)
this.state = {
background: 'color',
pickedWall: false,
}
const handleChangeComplete = (e) => {
this.setState(prevState => ({
...prevState,
pickedWall: true,
background: e.target.value,
}))
}
render() {
const { x, y } = this.props
const { background, pickedWall } = this.state
const { handleChangeComplete } = this
return <SketchPicker {...{ x, y, background, handleChangeComplete, pickedWall }} />
}
在你的组件中...
const SketchPicker = ({
x,
y,
background,
pickedWall,
handleChangeComplete,
}) => {
return (
<div>
<SomeDiv onClick={(e) => handleChangeComplete(e)}>
...your code
</SomeDiv>
<Fragment>
{pickedWall && <WallPicker {...{ x, y, background }} />}
</Fragment>
</div>
)
}
关于javascript - 如何将类组件中的 props 发送到功能组件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60280280/
我是一名优秀的程序员,十分优秀!