8000 多页面共用一个 state,如何拿到state中的值 · Issue #13 · recurrying/refast · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

多页面共用一个 state,如何拿到state中的值 #13

New issue

Have a question about this project? Sign up for a free Gi 8000 tHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
byk04712 opened this issue May 23, 2019 · 0 comments
Open

多页面共用一个 state,如何拿到state中的值 #13

byk04712 opened this issue May 23, 2019 · 0 comments

Comments

@byk04712
Copy link
byk04712 commented May 23, 2019

logincA.js

export default {

  defaults() {
    return {
       list: []
    }

    fetchList(ctx){
        // 这里网络请求获取到数据并setSatate 到 list 中
       ctx.setState({
           list: ['a','b','c']
       })
    }

    getList(ctx) {
        // PageB 页面调用此函数,获取到的 list 是个空数组
        const list = ctx.getState().list
        console.log('list', list) // list 是空的数据
    }
}

PageA.js

import logicA from './logicA'

class A extends Component {
    constructor(props){
        super(props, logicA)
    }

    componentDidMount() {
        this.dispatch('fetchList')
    }
}

PageA 获取到数据后,然后跳转到 PageB 页面

PageB.js

import logicA from './logicA'

class B extends Component {
    constructor(props){
        super(props, logicA)
    }

    componentDidMount() {
        this.dispatch('getList')
    }
    
}

PageB 页面中如何在调用的时候依然能通过 ctx.getState() 拿到 list 当中的数据?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant
0