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"/>
</template>
methods:{
        refresh() {
            this.$refs.tabs.refreshs();
        }
    },

猜你喜欢

转载自www.cnblogs.com/wd163/p/13168779.html