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>
发布了94 篇原创文章 · 获赞 42 · 访问量 13万+

猜你喜欢

转载自blog.csdn.net/qq_29483485/article/details/102369881