1、場景:vue
項目需求是:在課程詳情頁 點擊 相關課程 還在當前頁面看此課程詳情;vue-router
功能實現:這時候點擊相關課程須要從新加載刷新當前路由app
2、’解決的辦法及遇到的問題ide
3、推薦解決方法:this
1.在App.vue,聲明reload方法,控制router-view的顯示或隱藏,從而控制頁面的再次加載。code
<template> <div id="app"> <router-view v-if="isRouterAlive"/> </div> </template> <script> export default { name:"app", provide(){ return{ reload:this.reload } }, data(){ return{ isRouterAlive:true //控制router-view的顯示或隱藏 } }, methods:{ reload(){ this.isRouterAlive = false; this.$nextTick(()=>{ this.isRouterAlive = true; }) } } } </script>
2.在須要用到刷新的頁面中注入App.vue組件提供(provide)的 reload 依賴,在邏輯完成以後,直接this.reload()調用,便可刷新當前頁面。router
注入reload方法blog
直接調用 this.reloadip