vue实现不刷新整个页面刷新数据

vue 或者iview的框架里有个方法:需要刷线当前组件页面,不用刷线整个页面:网上有很多方法,但是不好使,都是刷新整个页面的方法,最终自己找到了方法,很好用:

vue实现无刷新加载数据,使用的技术是依赖注入 关键字为provide inject
在App.vue中

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

 然后在需要使用这个方法的的vue组件中注入这个方法

data(){},
inject:["reload"]


//然后在你想要使用的地方 使用就可以了
this.reload()

 
原文地址:https://www.cnblogs.com/mahmud/p/11864145.html