VUE页面刷新问题

1). location方式
location.reload()

缺点:刷新页面,卡白
2). router方式
this.$router.go(0)
缺点:同一问题,比一好点
3). provide/inject方式
App.vue
<router-view v-if="isRouterAlive"></router-view>

<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>

缺点:暂时比较不错的解决方案,重点控制`router-view`
posted @ 2019-01-15 17:10  青春筑梦  阅读(436)  评论(1编辑  收藏  举报