vue關於this.$refs.tabs.refreshs()刷新組件,緩存


當更改了用戶信息后,需要刷新頁面或者組件。

1.當前組件刷新。定義一個請求用戶信息的方法,在需要時調用:

sessionStorage.setItem('userInfo',JSON.stringify(this.userInfo));

2.刷新父組件。

子組件某個需要的地方:

  this.$emit('refresh');  
父組件:
methods:{
        refresh() {
            this.userInfo = JSON.parse(sessionStorage.getItem('userInfo'));
        }
    },
3.非關系組件:
父組件:
<template>
  //需要刷新的組件(非關系組件)
   <top-bar ref="tabs"/>
   <div class="content">
         //子組件
         <router-view class="animated zoomIn"  @refresh="refresh"></router-view>
   </div>
</template>
methods:{
        refresh() {
            this.$refs.tabs.refreshs();
        }
    },


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM