Giter VIP home page Giter VIP logo

Comments (5)

weiq avatar weiq commented on August 17, 2024

@chenwangji 本身put就是异步的,所以不会阻塞,你的这个需求可以用take来解决

*save({ payload }, { call, put, select, take }) {
      const { values, success } = payload;
      const { pageData } = yield select(state => state.crud);
      yield put({
        type: '@request',
        payload: {
          notice: true,
          url: '/crud/save',
          data: values
        }
      });
      // 等待@request结束
      yield take('@request/@@end');
      yield put({
        type: 'getPageInfo',
        payload: { pageData }
      });
      success();
    }

from dva-boot-admin.

chenwangji avatar chenwangji commented on August 17, 2024

感谢!
可以再问个问题吗,我如何拿到 @request 之后,从后端返回的数据,类似于

const res =  yield put({
    type: '@request',
    payload: {
      url: '/admin/userManage/deleteUserInfo',
      data: {
        id: records.map(item => item.rowKey)[0]
      },
      success
    }
})

yield take('@request/@@end')

if (res) {
   yield put({
        type: 'getPageInfo',
        payload: { pageData }
    }) 
}

from dva-boot-admin.

weiq avatar weiq commented on August 17, 2024

使用 yield select()

from dva-boot-admin.

chenwangji avatar chenwangji commented on August 17, 2024

select 是不是只能获取到 state 中的值啊,但是我有些请求并不会把返回结果存到 state, 那样用 select 就拿不到了

from dva-boot-admin.

weiq avatar weiq commented on August 17, 2024

不放到state里 select 是取不到的,但是应该有变通的办法吧,是不是可以换个思路来考虑问题

from dva-boot-admin.

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.