Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 在我的屏幕上看不到img-(代码)_Reactjs - Fatal编程技术网

Reactjs 在我的屏幕上看不到img-(代码)

Reactjs 在我的屏幕上看不到img-(代码),reactjs,Reactjs,我将jquery添加到index.html中 但我不知道为什么我看不到阿凡达的url和即将到来的日期的名称 我检查-日期有效(删除此处的登录名) 如何查看图像和名称? 我做错了什么 var Card = React.createClass({ getInitialState: function(){ return {}; }, componentDidMount: function(){ // we need to define the callback inf

我将jquery添加到index.html中 但我不知道为什么我看不到阿凡达的url和即将到来的日期的名称

我检查-日期有效(删除此处的登录名)

如何查看图像和名称? 我做错了什么

var Card = React.createClass({

  getInitialState: function(){
    return {};
  },

  componentDidMount: function(){

    // we need to define the callback info as component => to get the prop/state
    var component = this;

    // get data ( name ) from AJEX info => the return object is the arg 'data' 
    $.get("https://api.github.com/users/" + this.props.login, function(data){

      component.setState(data);    // set component as component of the callback data => in h3 we can get the data to show on ui 


    });
  },

  render: function(){
    return (
      <div>
        <img src={this.state.avatar_url} width="80"/>
        <h3>{this.state.name}</h3>
        <hr/>
      </div>
    );
  }
});




var Main = React.createClass({
  render: function(){
    return (
      <div>
        <Card login="myLogInName" />
      </div>
    )
  }
});

React.render(<Main />, document.getElementById("root"));
var Card=React.createClass({
getInitialState:函数(){
返回{};
},
componentDidMount:function(){
//我们需要将回调信息定义为component=>以获取prop/state
var分量=此;
//从AJEX info获取数据(名称)=>返回对象是参数“数据”
$.get(”https://api.github.com/users/“+this.props.login,函数(数据){
setState(data);//将组件设置为回调数据的组件=>在h3中,我们可以获得要在ui上显示的数据
});
},
render:function(){
返回(
{this.state.name}

); } }); var Main=React.createClass({ render:function(){ 返回( ) } }); React.render(,document.getElementById(“根”));
在对Reactjs进行v.16更新后,不推荐使用React.createClass创建组件。
为了以这种方式创建react组件,您需要使用
var createReactClass=require('create-react-class')在文件顶部包含
create-react-class

使用React.createClass创建组件在Reactjs的v.16更新后被弃用。
为了以这种方式创建react组件,您需要使用
var createReactClass=require('create-react-class')在文件顶部包含
create-react-class

响应中的
name
属性似乎是
null
。另外,我使用了
login
属性作为一个值

我还更新了代码以使用ES6语法,其优点之一是箭头函数可以自动绑定
this

类卡扩展React.Component{
建造师(道具){
超级(道具);
此.state={
头像url:null,
登录名:null
};
}
componentDidMount=()=>{
//从AJAX信息获取数据(名称)=>返回的对象是参数“data”
$.get(”https://api.github.com/users/“+this.props.login,数据=>{
此设置状态(数据);
});
}
render(){
返回(
{this.state.login}

); } }; 类Main扩展了React.Component{ render(){ 返回( ) } }; render(,document.getElementById(“根”))
响应中的
name
属性似乎是
null
。另外,我使用了
login
属性作为一个值

我还更新了代码以使用ES6语法,其优点之一是箭头函数可以自动绑定
this

类卡扩展React.Component{
建造师(道具){
超级(道具);
此.state={
头像url:null,
登录名:null
};
}
componentDidMount=()=>{
//从AJAX信息获取数据(名称)=>返回的对象是参数“data”
$.get(”https://api.github.com/users/“+this.props.login,数据=>{
此设置状态(数据);
});
}
render(){
返回(
{this.state.login}

); } }; 类Main扩展了React.Component{ render(){ 返回( ) } }; render(,document.getElementById(“根”))


你能在渲染方法中执行console.log()并确认你正确获取了这个.state.avatar\u url吗?@G\u的最新反应。。。请告诉我它是如何完美工作的。我得到了一张照片,我看到它在你身上起作用。不明白我的不在我的环境中您是否在控制台中看到任何错误?这是您的整个组件还是您删除了不必要的代码使其变得简单?您能在渲染方法中执行console.log()并确认您正确获取了这个.state.avatar\u url吗?@G\u是react上的新功能。。。请告诉我它是如何完美工作的。我得到了一张照片,我看到它在你身上起作用。不明白我的不在我的环境中您是否在控制台中看到任何错误?是您的整个组件,还是您删除了不必要的代码以使其变得简单?