vue刷新页面时候去掉闪烁

在router-view里添加v-if判断

   

然后在添加provide()以及reload方法

   provide() {
            return {
                reload: this.reload
            }
        },
        data() {
            return {
                // 通过isRouterAlive来控制router-view的显示和隐藏 从而控制页面再次加载
                // 优化window.reload或者router.go(0)导致的页面重新加载 闪烁
                isRouterAlive: true
            }
        },
         methods: {
            reload() {
                this.isRouterAlive = false
                this.$nextTick(() => {
                    this.isRouterAlive = true
                })
            }
        }

在需要进行刷新的页面注入reload方法,然后直接使用就ok了

inject: ['reload'], // 注入reload方法 控制页面重新加载

你可能感兴趣的:(vue-js)