小编dj2*_*017的帖子

使用this.refs的弃用警告

我有一个React组件,我想在单击时切换一个css类.

所以我有这个:

export class myComponent extends React.Component {
  constructor() {
    super();
    this.state = { clicked: false };
    this.handleClick = this.handleClick.bind(this);
  }

  render() {
    return (
      <div>
        <div onClick={this.clicked}><span ref="btn" className="glyphicon">&nbsp;</span></div>
      </div>
    );
  }

  handleClick() {
    this.refs.btn.classList.toggle('active');
  }

  componentDidMount() {
    this.refs.btn.addEventListener('click', this.handleClick);
    this.setState({
      clicked: this.state.clicked = true,
    });
  }

  componentWillUnmount() {
    this.refs.btn.removeEventListener('click', this.handleClick);
    this.setState({
      clicked: this.state.clicked = false,
    });
  }
}
Run Code Online (Sandbox Code Playgroud)

这个问题是ESLint不断告诉我"this.refs"已经折旧了.

我该怎么做?如何修复它以便不使用折旧代码?

javascript reactjs

38
推荐指数
1
解决办法
2万
查看次数

将AngularJS迁移到Angular 4,5(使用DEMO)

我正在研究将当前的Angular 1项目迁移到Angular 4的方法.

选项包括ng-forward,ngUpgraderewrite.

我正在考虑重写它,但有一点扭曲.

  • 我保留当前的申请表
  • 开始写新的并行
  • 所有新的NG4重写,我想用......所以一点一点地换句话说.

有人试过这个或知道更好的方法吗?

javascript angularjs ng-upgrade angular angular-hybrid

16
推荐指数
1
解决办法
1万
查看次数

Javascript ES6从URL获取JSON(无jQuery)

我想知道是否有任何ES6方式从网址获取json或其他数据.

jQuery GET和Ajax调用很常见,但我不想在这个中使用jQuery.

典型的调用如下所示:

var root = 'http://jsonplaceholder.typicode.com';

$.ajax({
  url: root + '/posts/1',
  method: 'GET'
}).then(function(data) {
  console.log(data);
});
Run Code Online (Sandbox Code Playgroud)

或者没有像这样的jQuery:

function loadXMLDoc() {
    var xmlhttp = new XMLHttpRequest();

    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == XMLHttpRequest.DONE ) {
           if (xmlhttp.status == 200) {
               document.getElementById("myDiv").innerHTML = xmlhttp.responseText;
           }
           else if (xmlhttp.status == 400) {
              alert('There was an error 400');
           }
           else {
               alert('something else other than 200 was returned');
           }
        }
    };

    xmlhttp.open("GET", "ajax_info.txt", true);
    xmlhttp.send();
}
Run Code Online (Sandbox Code Playgroud)

我的问题是......有没有新方法可以做到这一点......例如ES6还是它仍然是一样的?

javascript ecmascript-6 es6-promise

4
推荐指数
2
解决办法
1万
查看次数