如何将布尔值传递给控件react.js

发布于 2025-02-11 16:52:39 字数 648 浏览 1 评论 0原文

如何将布尔值传递给控件react.js

类应用程序扩展react.component {

constructor(props) {

  **// Calling super class constructor**
  super(props);
    
  **// Creating state**
  this.state ={
    video.controls= false

  }
  
}
 
render() {
    return (
    
        <div className= "container">
            <video controls>
            <source src="http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" type="video/mp4"></source>
            <p>Your browser doesn't support HTML5 video.</p>
            </video>
        </div>
    );
} }

导出默认应用程序;

How to pass Boolean value to the controls React.Js

class App extends React.Component {

constructor(props) {

  **// Calling super class constructor**
  super(props);
    
  **// Creating state**
  this.state ={
    video.controls= false

  }
  
}
 
render() {
    return (
    
        <div className= "container">
            <video controls>
            <source src="http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" type="video/mp4"></source>
            <p>Your browser doesn't support HTML5 video.</p>
            </video>
        </div>
    );
} }

export default App;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谷夏 2025-02-18 16:52:39

您必须将状态值传递到&lt; video&gt;标签中。为此,您需要在代码中应用两个更改:

第一个更改,作为一个建议,请勿直接在您的州内创建一个嵌套对象,如果您想添加一个嵌套对象,我绝对建议您使用格式:视频:{控制:false}当前video.controls = false value的格式。因此,它将结束是这样的:

this.state = {
  videoControls: false
}

然后,您可以将状态包装到对象键{}::

<video controls={this.state.videoControls}>
  {/* Your code comes here... */}
</video>

You have to pass the state value into the <video> tag. To do it, you need to apply two changes in your code:

The first one, and as a suggestion, is to not create a nested object directly in your state, if you want to add a nested object I would definitely recommend you to use the format of: video: { controls: false } insead of your current video.controls = false value. So it would end being something like this:

this.state = {
  videoControls: false
}

And then you could use the state into the tag by wrapping it into object keys {}:

<video controls={this.state.videoControls}>
  {/* Your code comes here... */}
</video>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文