Vue 刷新当前页面

1). location方式
location.reload()
2). router方式
this.$router.go(0)
3). provide/inject方式
  • App.vue
<script>
  export default {
    name: 'App',
    // 提供reload方法
    provide: function () {
      return {
        reload: this.reload
      }
    },
    // isRouterAlive控制显示
    data: function () {
      return {
        isRouterAlive: true
      }
    },
    methods: {
      // 刷新方法
      reload: function () {
        this.isRouterAlive = false;
        // 该方法会在dom更新后执行
        this.$nextTick(function () { this.isRouterAlive = true })
      }
    }
  }
</script>
  • home.vue
<script>
  export default {
    name: 'home',
    // 注入reload, AppVue中注册
    inject: ['reload'],
    methods: {
      // 退出登陆
      logout: function () {
        // 刷新
        // location.reload()
        // this.$router.go(0)
        // 刷新当前页面
        this.reload();
      }
    }
  }
</script>

效果演示:


效果.gif
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 相关概念 混合开发和前后端分离 混合开发(服务器端渲染) 前后端分离后端提供接口,前端开发界面效果(专注于用户的交...
    他爱在黑暗中漫游阅读 7,957评论 4 45
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 176,235评论 25 709
  • 云雾缭绕,轻纱似的缈云围绕在澄澈的水潭周围,四处各种灵草横杂凌乱的肆意生长在这里,暖暖的清风,环绕在潭边。在...
    惟欲暮雪阅读 1,873评论 0 0
  • 换成这个号了哟 悄悄的
    你看嘛是我啊阅读 2,286评论 0 0

友情链接更多精彩内容