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