鍍金池/ 問答/HTML/ dva network 頁面加載順序不對,如何修改

dva network 頁面加載順序不對,如何修改

我的投票頁面網(wǎng)址是:http://localhost:8000/teamBuilding/poll/pollDetail/103
我投了2票,投完后只顯示投了1票。
刷新頁面后顯示投了2票。
數(shù)據(jù)都是對的,提交后數(shù)據(jù)庫內(nèi)的數(shù)據(jù)也是對的。
圖片描述

250表示投250一票,傳到數(shù)據(jù)庫
105表示加載投票結(jié)果
251表示投251一票,傳到數(shù)據(jù)庫

等于說我在數(shù)據(jù)傳到數(shù)據(jù)庫前就讀結(jié)果了,所以讀到結(jié)果是錯的,但數(shù)據(jù)庫里面數(shù)據(jù)是對的。所以再刷新后顯示結(jié)果又對了。

圖片描述

這是我的提交函數(shù)。checkedList里面是我選的選項(xiàng)。顯示數(shù)據(jù)是對的,是2票。然后第一個dispatch,把數(shù)據(jù)傳到model去在數(shù)據(jù)庫中create這2條數(shù)據(jù)。
第二個dispatch意思是去往pathname:${data.id}這個頁面(http://localhost:8000/teamBuilding/poll/pollDetail/103),還是原來的頁面。我不知道刷新頁面怎么寫所以就用了這種方式。location.reload();不行,會不提交數(shù)據(jù),只刷新頁面。

我的想法是換個方法回到這個頁面http://localhost:8000/teamBuilding/poll/pollDetail/103。有沒有大佬教一下?

回答
編輯回答
浪蕩不羈

dva管理狀態(tài)
在pollDetailModel中create方法來設(shè)置投票
接著異步進(jìn)行router.push

2017年8月30日 20:27
編輯回答
孤影
  const onClickpublish = () => {
    console.log("checkedList",checkedList)
    dispatch({
      type: 'pollDetail/create',
      payload: checkedList,
      pollId: data.id
    }).then(() => {
      dispatch(routerRedux.push({
        pathname: `${data.id}`,
      }))
    });
  }
2018年8月16日 22:43