vue 使用this.reload方法刷新頁面配置

1.在vue(app.vue文件)裏配置:

<template>
  <div>
    <router-view v-if="isRouterAlive" />
  </div>
</template>

<script>
export default {
	provide() { //提供reload方法
	    return {
	        reload: this.reload
	    }
	},
	data() {
	    return {
	        isRouterAlive : true
	    }
	},
	methods:{ //刷新方法
	    reload() {
	        this.isRouterAlive = false;
	        this.$nextTick(function() {
	            this.isRouterAlive = true
	        })
	    },
	}
};
</script>

在組件中使用:

<script>
    export default {
        inject: ['reload'],
        methods:{
            refresh() {
                this.reload();
            }
        }
    }
</script>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章