小编典典

为什么我会不断获取tsx文件中的类方法“ componentDidMount”必须被“私有”,“公共”或“受保护”警告屏蔽?

reactjs

我不确定应该在我的反应类组件中标记什么方法。我在以下方法上遇到此错误:componentDidMount,componentDidUpdate,componentWillUpdate和render

这是我拥有的基本组件:

import * as React from 'react';

const { Component } = React;

export default class Loading extends Component<{}, {}>  {
  componentDidMount() {
    console.log('....something....');
  }
  componentDidUpdate() {
    console.log('....something....');
  }
  componentWillUpdate() {
    console.log('....something....');
  }

  render() {
    const style = {
      background: '#f5f5f5',
      height: '100%',
      padding: '20px',
      textAlign: 'center',
      transition: 'all 0.5s linear',
      width: '100%'
    };
    return (
      <div id='app-loader' className='rounded' style={style}>
        <div className='loader large block rounded'>Loading...</div>
      </div>
    );
  }
}

我不能放私有的render()等,因为那会破坏组件。


阅读 355

收藏
2020-07-22

共1个答案

小编典典

这是tslint 成员访问规则。

tslint.json中 ,更改:

"member-access": true

至:

"member-access": [true, "no-public"] // Or false. Read the rule and see what you want.
2020-07-22