【问题标题】:spread operator is not working in react as {...this.state.attributes}传播运算符不作为 {...this.state.attributes} 工作
【发布时间】:2019-01-13 03:05:39
【问题描述】:

我正面临问题出乎意料的令牌,因为...这在 React 中不能用作属性。

<button {...this.state.attributes}> Save </button>

this 在此范围内具有价值。 提前致谢。

问候, Shraddha Agrawal

【问题讨论】:

  • 必须是三个点:-P,能分享一下属性包含什么

标签: javascript reactjs spread-syntax


【解决方案1】:

甚至可能是一个错字...这个而不是..这个。见下文。

        import React, { Component } from 'react';
        import logo from './logo.svg';
        import './App.css';

        class App extends Component {

          state = {className:"button", style:{color: 'red'}}

          render() {
            return (
              <div>
                <h1>Hello World</h1>
                <button {...this.state}>Hello World</button>
              </div>
            );
          }
        }

        export default App;

【讨论】:

  • 对不起...仅此
猜你喜欢
  • 2019-01-23
  • 2022-08-05
  • 2015-01-12
  • 1970-01-01
  • 2013-09-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-09
相关资源
最近更新 更多