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

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM