Vue刷新页面的三种方式

443 阅读1分钟
  1. windou.location.reload()
  2. this.$router.go(0)
  3. 首先在APP.vue里面写控制的

<template>  
    <div id="app">    
    <router-view v-if="isReload" />  
    </div>
</template>
<script>
export default {  name: 'App',  
    provide() {    
        return {      
            reload: this.reload    
        }  
    },  
    data() {    
        return {      
            isReload: true
        }  
    },  
    methods: {    
        reload() {      
            this.isReload = false      
            this.$nextTick(function() {        
                this.isReload = true      
            })    
        }  
    }
}
</script>

需要刷新页面的组件里这样写:

export default {
    inject:['reload'],                                 //注入App里的reload方法
    data () {
        return {
    	.......
        }
    }
}

需要刷新页面的代码块中使用:

this.reload()