【问题标题】:How to call React api component into main component?如何将 React api 组件调用到主组件中?
【发布时间】:2017-09-29 10:40:56
【问题描述】:

我是 React 新手,我在组件中编写了一些 API 调用,当我尝试在我的主组件中添加导入时,它显示以下错误 ./src/containers/Ready_bricksapi.jsx 中的错误 未找到模块:错误:无法解析“D:\Brickzle (1)\src\containers”中的“导出”

@./src/containers/Ready_bricksapi.jsx 1:0-65

@./src/containers/homepage.jsx

@./src/containers/app-route.jsx

@./src/entry-points/client.jsx

@multi webpack-dev-server/client?http://localhost:8080webpack/hot/dev-server ./src/entry-points/client.jsx

import React, { Component } from 'react';


export  class ReadyBricks extends Component {
   Constructor(props) {
     Super(props);
     this.setState = {
       bricksList: []


     };


   }
  componentDidMount() {
    this.readyBrick();
  };

     readyBrick() {
     console.log("inside get api");
     const url = '\'http://10.10.1.42:8070/api/user/brick/getBrickList?id=0\'';
       fetch(url, {
         method: 'GET',
         headers: {
           'Content-Type': 'application/json',
           'auth':'sdf345dvdfg4dfgdf435fghfhfg45123'
         },
       })
         .then(function (response) {
           let bricksList=response.results;
           return bricksList;
           console.log(bricksList);
         })

         .catch(function(error) {
           console.log(JSON.stringify(error));
         });





     }


  render() {
    const ReadyBricks = this.state.bricksList.map((item) => {
      return <div className="col-xs-12">
        <div className="col-xs-6">
          <p>Ready Brick Arts </p>
          {item}
        </div>
      </div>
    });


  }

 }

现在我的问题是如何将此 jsx 文件添加到我的组件中

【问题讨论】:

  • @shota 你能推荐一些反应 api 调用的链接
  • 请找一个 React 初学者教程,它会告诉你怎么做。
  • 你能推荐一些链接吗,因为那是收费的

标签: javascript reactjs


【解决方案1】:

我不知道您所说的“应付款”是什么意思 - 您是否愿意为咨询付费?我对此并不感兴趣。

这是你的做法。在某个页面(通常是 index.html)上,您指定一个 HTML 元素来接收来自 React 的顶级 render()

假设您的 HTML 如下所示

<body>
  <div id="myDiv"></div>
</body>

在你的脚本中你这样做:

React.render(
    <ReadyBricks/>,
    document.getElementById('myDiv')
);

这样会将您的 ReadyBricks 组件渲染到 myDiv div 中。

但如果你还不知道这一点,并且你想用 React 构建东西,那么你确实需要学习一门课程。

【讨论】:

    猜你喜欢
    • 2021-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-04
    • 2016-09-27
    • 1970-01-01
    • 2020-03-15
    相关资源
    最近更新 更多