当前位置:网站首页>Dva中在effects中获取state的值
Dva中在effects中获取state的值
2022-04-23 05:43:00 【林仔520】
这里写自定义目录标题
以自己一个实际工程项目为例做演示
1. State定义如下
// 设置初始值
state: {
productDate: {
code: '',
result: {
data:[]
},
status: 200,
},
deviceId: '888'
},
2. 项目需求
需要获取state中deviceId的初始值
3. effects中实现
// 调用服务端接口,获取数据
/** * 以 key/value 格式定义 effect。用于处理异步操作和业务逻辑,不直接修改 state。由 action 触发,可以触发 action,可以和服务器交互,可以获取全局 state 的数据等等。 */
effects: {
*fetchProducts({
payload },{
call, put, select}){
const deviceId = yield select(state => state.product.deviceId);
console.log("deviceId = "+deviceId);
const data = yield call(getProductDatenew, deviceId)
yield put({
type: 'setProducts',
payload: data
})
}
},
4. 结果如下所示
版权声明
本文为[林仔520]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_37955704/article/details/117253104
边栏推荐
猜你喜欢
Ora: 28547 connection to server failed probable Oracle net admin error
手动删除eureka上已经注册的服务
SQL statement simple optimization
Data mining -- understanding data
Jiugong magic square - the 8th Lanqiao provincial competition - group C (DFS and comparison of all magic square types)
MySQL的锁机制
软件架构设计——软件架构风格
Manually delete registered services on Eureka
Fletter next generation graphics renderer impaller
lambda表达式
随机推荐
合约锁仓漏洞
mysql如何将存储的秒转换为日期
事实最终变量与最终变量
Understand the current commonly used encryption technology system (symmetric, asymmetric, information abstract, digital signature, digital certificate, public key system)
The role of brackets' [] 'in the parameter writing method in MDN documents
Mysql 查询使用\G,列转行
No.1.#_6 Navicat快捷键
【华为机试】考试得分总数(如何处理答错的情况?回溯一次,代表答错一题)
AcWing 1096. Detailed notes of Dungeon Master (3D BFS) code
橙单微服务之批量导入
[machine learning] scikit learn introduction
mysql sql优化之Explain
STL function library
框架解析2.源码-登录认证
What is JSON? First acquaintance with JSON
io. lettuce. core. RedisCommandExecutionException: ERR wrong number of arguments for ‘auth‘ command
Insert picture in freemark
Hotkeys, interface visualization configuration (interface interaction)
基于ssm 包包商城系统
Package mall system based on SSM