How to correctly migrate the code from angularjs to reactjs

后端 未结 1 1091
悲&欢浪女
悲&欢浪女 2021-01-29 07:13

I\'m trying to migrate the code from angular to react. Not sure if it\'s correct, just need some help if I\'m going in the right direction or not. I don\'t know angular so I\'m

1条回答
  •  南笙
    南笙 (楼主)
    2021-01-29 07:48

    Try this, Hope it will work.

    class MyComponent extends React.Component {
      constructor(props) {
        super(props);
        this.state = {
          textdata: [],
          textlen: 0
        };
      }
    
    textanalysis(){  
    fetch('/api/analyse', {
        method: 'POST',
        body: JSON.stringify({
          snippetdesc: 'snippetDescription'
        }),
        headers: {
          "Content-type": "application/json; charset=UTF-8"
        }
      })
      .then(response =>  response.json())
      .then((textdata) => {
          this.setState({
            textdata : textdata.data,
            textlen : snippetDescription.split(' ').length
          });
        },(error) => {
              console.log(error)
        })
    }  
    }
    

    0 讨论(0)
提交回复
热议问题