【问题标题】:Expected property shorthand预期属性简写
【发布时间】:2021-06-06 08:40:51
【问题描述】:

我是新手,遇到了这个错误,不太清楚这意味着什么。

错误:tree:tree 的预期属性简写 - 由 eslint 触发?

import {
  tree, tree1, tree2, tree3, tree4,
} from './Tree';

export default class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      tree: tree,
      downloadingChart: false,
      config: {},
      // highlightPostNumbers: [1],
    };
  }

【问题讨论】:

    标签: reactjs jsx eslint


    【解决方案1】:

    ESLint 希望你在状态对象中使用速记:

        this.state = {
          tree,
          downloadingChart: false,
          config: {},
          // highlightPostNumbers: [1],
        };
    

    如果您引用的变量与您定义的键同名,则不必声明键和值。你也可以使用 ESLint 的 object shorthand rules 来禁用它。

    【讨论】:

      【解决方案2】:

      当 key 的 name 与 value 相同时。你可以写一次作为速记。

      this.state = {
        tree,
      };
      

      【讨论】:

        【解决方案3】:

        如果您的状态属性树与导入的值树同名,请尝试this.state = {tree} ,不要使用第二个。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2018-09-03
          • 2020-12-19
          • 1970-01-01
          • 1970-01-01
          • 2016-02-14
          • 2017-04-06
          • 2019-01-30
          • 2017-03-05
          相关资源
          最近更新 更多