vue页面跳转没有刷新数据

àì夳堔傛蜴生んèń 2023-01-07 14:26 277阅读 0赞

情景:

A页面新增数据,B页面查看新增数据,B页面查看不到刚刚新增的数据

原因:

页面B加载时,没有执行created()函数,所以可能是使用了缓存数据

解决方法:

将created()或mounted()函数中执行获取数据的方法放到activated()函数中,

activated()函数:每次页面加载就会执行该函数

同时该函数也可以获取到路由传递过来的参数

  1. methods:{
  2. /** * 获取数据 */
  3. getDataList(){
  4. request({
  5. url:'standardClassify/querySecondIcsStandard',
  6. methods: 'get',
  7. params:{ parentCode:this.parentCode}
  8. }).then((rsp)=>{
  9. if(rsp.resultCode==='0'){
  10. this.secondDataList=rsp.data
  11. }else {
  12. this.$message({
  13. message:'请求数据错误',
  14. type:'error',
  15. duration:1500
  16. })
  17. }
  18. })
  19. },
  20. },
  21. activated(){
  22. this.parentCode=this.$route.query.item.code
  23. this.getDataList();
  24. }

发表评论

表情:
评论列表 (有 0 条评论,277人围观)

还没有评论,来说两句吧...

相关阅读