ast*_*one 11 input placeholder reactjs react-jsx
我有一个输入标签,我正在尝试将占位符的内容设置为组件的道具.在编译JSX并在浏览器中运行它之后,占位符根本不显示.它也没有抛出任何错误.我怎样才能做到这一点?
<input type="text" onChange={this.props.handleChange} placeholder={this.props.name} />
Run Code Online (Sandbox Code Playgroud)
这个代码在子组件中似乎没有任何问题.当你实现它时,占位符应该显示得很好.
这是我在父母中设置的方式:
import React, { Component } from 'react';
import Title from'./Title';
import TestList from'./TestList';
export default class Layout extends Component {
constructor() {
super();
this.state = {
title: 'Moving Focus with arrow keys.',
placeholder:'Search for something...'
};
}
render() {
return (
<div >
<Title title={ this.state.title } />
<p>{ this.getVal() }</p>
<TestList placeholderText={this.state.placeholder} />
</div>
);
}
}
Run Code Online (Sandbox Code Playgroud)
以下是我在孩子中展示它的方式:
import React, { Component } from 'react';
export default class TestInput extends Component {
constructor(props){
super(props);
};
render() {
return (
<div>
<input type="search" placeholder={this.props.placeholderText} />
);
}
}
}
Run Code Online (Sandbox Code Playgroud)
有点迟到的回复,但希望它有所帮助!:-)