• Log in
Anwen  Share and Create
  • Book
  • Movies
  • Music
  • SF
  • Goodlink
  • Asks
  • Eyeopen
  • Create

[问与答] 使用 redux 中出现了问题,求教。

Sharer: V2EX January 12, 2020 at 5:56 am
Link Share :https://www.v2ex.com/t/637322#reply9 - via RSS

function allReducer(state=Map({}), action){ let newstate = Map({}) switch (action.type) {

    case SET_CSRFTOKEN: 
        return state.set("csrftoken", action.csrftoken)

    case START_WORK: {
        console.log('开工')
        console.log(state)

        axios({
            method: 'post',
            headers: {'X-CSRFToken': state.get('csrftoken')},
            url: '/start/',
            data: {startdate:action.startdate,enddate:action.enddate},   
        }).then(function (response) {
            newstate = state.set("atwork", response.data.atwork)
            console.log(newstate)
          });
        console.log(newstate)
        return newstate
    }

倒数第二个 console.log(newstate)可以看到里面是有值的,最后一个 console.log(newstate)里面就是空的了,没有任何值。请问这是怎么回事?

作者暂无likerid, 赞赏暂由本网站代持,当作者有likerid后会全部转账给作者(我们会尽力而为)。

Tips: Until now, everytime you want to store your article, we will help you store it in Filecoin network. In the future, you can store it in Filecoin network using your own filecoin.


Support author:
Author's Filecoin address:
Or you can use Likecoin to support author:

0 0

2012-2018 Anwen All of our posts are default licensed under CC BY 4.0 About Help Changelog Telegram
Today Quote: 永远不要让道德感阻止你做正确的事情。 -- 第一基地市长萨尔弗·哈丁(阿西莫夫《基地》)