Coder Social home page Coder Social logo

如何和服务端进行交互? about ice HOT 4 CLOSED

alibaba avatar alibaba commented on May 3, 2024
如何和服务端进行交互?

from ice.

Comments (4)

chenbin92 avatar chenbin92 commented on May 3, 2024

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

from ice.

adamqqqplay avatar adamqqqplay commented on May 3, 2024

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

from ice.

chenbin92 avatar chenbin92 commented on May 3, 2024

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


  componentDidMount() {
    this.getData();
  }

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

from ice.

adamqqqplay avatar adamqqqplay commented on May 3, 2024

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

from ice.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.