比如: 我想在request.js
中拿到store
中的token
, 应该怎么做?
我看redux
文档是这么写的:
import { createStore } from 'redux'
let store = createStore(todoApp)
可是dva
创建的项目中, 这里的store
好像并没有经过我手...
request.js 是从 effect 调的,effect 可以拿到 state,然后传给 request.js。
那岂不是每次请求都要取一次token, 能不能在request.js里拿到token自动加上
不能,request.js 里不能直接取 state 。
@bowencool 你这种需求可以创建一个全局对象,自己来维护,需要管理的数据就是数据量小,但是使用频繁的。
@yvanwangl 多谢提醒
model中,effects中,怎么调用state呢???
@xiaofengqqcom123 select
可以通过app._store方式获取
ref: Dva 源码解析 | DvaJS
这样获取呢,多看文档哈。
window.g_app._store
window.g_app._store.dispatch
文档地址:
https://umijs.org/zh/guide/with-dva.html#%E9%85%8D%E7%BD%AE%E5%8F%8A%E6%8F%92%E4%BB%B6
Most helpful comment
可以通过app._store方式获取