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()