vue 局部刷新

1. App.vue里面写上如下代码

<template>
    <div id="app">
    	<router-view v-if="isRouterAlive"></router-view>
	</div>
</template>
<script>
    export default {
        name: 'App',
        provide () {    //父组件中通过provide来提供变量,在子组件中通过inject来注入变量。                                             
            return {
                reload: this.reload                                              
            }
        },
        data() {
            return{
                isRouterAlive: true                    //控制视图是否显示的变量
            }
        },
        methods: {
            reload () {
                this.isRouterAlive = false;            //先关闭,
                this.$nextTick(function () {
                    this.isRouterAlive = true;         //再打开
                }) 
            }
        },
    }
</script>

  2. 在需要刷新的组件写上

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

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

this.reload();

参考:https://blog.csdn.net/weixin_43885417/article/details/91310674

 

posted @ 2020-05-21 14:45  lethe666  阅读(575)  评论(0)    收藏  举报