Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何和服务端进行交互? #115

Closed
adamqqqplay opened this issue Feb 8, 2018 · 4 comments
Closed

如何和服务端进行交互? #115

adamqqqplay opened this issue Feb 8, 2018 · 4 comments

Comments

@adamqqqplay
Copy link

请问如何从服务端的api中获取数据更新数据?
我只看见了mock文件夹下的模拟数据,希望能介绍一下,教程里也没看见怎么操作

@chenbin92
Copy link
Collaborator

chenbin92 commented Feb 8, 2018

@adamqqqplay 在需要数据交互的区块内,我们通过 mock 的方式使用 axios 模拟异步加载数据的过程,在实际项目中,需要修改对应的 API 接口获取真实的数据从服务端获取数据,进行二次开发。我们推荐使用 axios 异步请求数据,但是并不限制你使用 axios,你也可以自己选择适合的技术方案。

@adamqqqplay
Copy link
Author

谢谢回复,还想问一下你们通过mock方式模拟axios加载数据的代码在哪个文件中呢?对应的API接口又是在哪呢?我在生成的项目里面找了一下没有找到。

@chenbin92
Copy link
Collaborator

chenbin92 commented Feb 9, 2018

@adamqqqplay 模拟数据加载的代码在 src/pages 对应的区块内,例如:


  componentDidMount() {
    this.getData();
  }

  /**
   * 异步获取数据
   */
  getData = () => {
    axios
      .get('/mock/xxx.json')
      .then((response) => {
        this.setState({
          tabData: response.data,
        });
      })
      .catch((error) => {
        console.log(error);
      });
  };

@adamqqqplay
Copy link
Author

adamqqqplay commented Feb 9, 2018

谢谢,这些帮助对于没接触过新兴前端框架的我很有帮助

ClarkXia added a commit that referenced this issue Nov 14, 2022
* feat: optimize folder

* fix: assets transform

* fix: optimze code

* fix: optimize code
ClarkXia added a commit that referenced this issue Nov 15, 2022
* feat: optimize folder

* fix: assets transform

* fix: optimze code

* fix: optimize code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants