Giter Site home page Giter Site logo

Comments (4)

fkpwolf avatar fkpwolf commented on May 25, 2024

仔细看了下,User 列表页面会渲染三次:

  1. model 初始化的时候加载一次,合理。
  2. effects 中的 const { data, headers } = yield call(usersService.fetch, { page }); 这一句会触发渲染。似乎没有必要,因为数据虽然取了回来,但是还没有塞到 model 中。
  3. reduce 中的 save 修改 model 后会触发一次,合理。

effect 应该是只能读取 state 而不能修改 state,要修改数据,只能在 reduce 中修改。这样 effect 里面的代码应该不会导致页面刷新啊?

from dva-example-user-dashboard.

fkpwolf avatar fkpwolf commented on May 25, 2024

找到原因了,第二次是由于Step 8. 通过 dva-loading 处理 loading 状态导致的,loading 状态是另外一个 model了,而fetch会修改这个状态。
由于 React 的机制,在数据没有变化的情况下组件是不会重新加载的,这样只是一个 loading 的变化对整个页面的性能影响关系不大。

from dva-example-user-dashboard.

allinshang avatar allinshang commented on May 25, 2024

不能只渲染一次么?

from dva-example-user-dashboard.

fkpwolf avatar fkpwolf commented on May 25, 2024

@allinshang 这里的做法是先显示空白数据页面,然后取到数据后再次渲染,这样用户体验会好点。当然你也可以先准备好数据,然后再跳转到这个页面。

from dva-example-user-dashboard.

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.