在'game-detail'頁(yè)面執(zhí)行this.$router.push()方法,跳轉(zhuǎn)到'game-detail',頁(yè)面不刷新。因?yàn)槁酚芍黧w沒變,變的只是傳遞的參數(shù)id所以從'game-detail?id=1'到'game-detail?id=2',并沒有跳轉(zhuǎn)。但是可以在watch里監(jiān)聽$route,監(jiān)聽到id的變化。后來(lái)我就在watch里邊監(jiān)聽路由,點(diǎn)擊后……重新調(diào)用了獲取頁(yè)面數(shù)據(jù)的methods函數(shù)。想通過刷新頁(yè)面數(shù)據(jù),再加上把滾動(dòng)條歸零,來(lái)模擬頁(yè)面的刷新。然后……點(diǎn)擊后……數(shù)據(jù)刷新了,頁(yè)面沒變化……父組件是通過props傳遞給子組件的,請(qǐng)問我應(yīng)該在子組件里怎么做呢?剛才百度了發(fā)現(xiàn)有的人說是在子組件里watch并且deep監(jiān)聽,然后我監(jiān)聽到數(shù)據(jù)變化了以后在子組件里進(jìn)行賦值也還是不行。父組件部分內(nèi)容:<child :data="dataList"/>data里邊:dataList: []this.$http.get().then((res)=>{ this.dataList.splice(0, this.dataList.length, ...res)
})watch部分:watch: {
$route(to, from) { this.$http.get().then((res)=>{ this.dataList.splice(0, this.dataList.length, ...res)
})
}
}子組件部分內(nèi)容:<div>{{ getData.name }}</div>props: ['data']data里邊:getData: this.data[0]
2 回答
慕神8447489
TA貢獻(xiàn)1780條經(jīng)驗(yàn) 獲得超1個(gè)贊
從代碼看 你的route壓根就沒有變化呀 怎么會(huì)出發(fā)watch呢
試試將getData寫成計(jì)算屬性
computed:{
getData (){ return this.data[0]
}
}添加回答
舉報(bào)
0/150
提交
取消
