查了网上一些资料说是
yield select(state => state.total)
但是实践输出后为undefined,后输出state值如下:
/**
* 消息模型
*/
export default {
namespace: 'longer',
state: {
total:0,
},
effects: {
/**
* 获取longer信息
* @param { id }
* @param {*} { call, put, select }
*/
*getLonger({ id }, { call, put,select }) {
const total = yield select((state)=>state ) // 测试输出state
// const total = yield select(_ =>_) 代码效果如上
console.log(total)
},
...
结果为所有的models的state值:
再将代码改成
/**
* 消息模型
*/
export default {
namespace: 'longer',
state: {
total:0,
},
effects: {
/**
* 获取longer信息
* @param { id }
* @param {*} { call, put, select }
*/
*getLonger({ id }, { call, put,select }) {
const total = yield select((state)=>state.longer.total ) // 测试输出state
// const total = yield select(_ =>_.longer.total) 代码效果如上
console.log(total)
},
...
输出结果为:0