没刷新是因为只有 query 变了,解决办法是: <template> <el-container class="full-height"> <el-header class="header-style"> <Header/> </el-header> <el-container> <el-aside class="aside-width"> <Menu/> </el-aside> <el-main class="main-container"> // 通过 isReloadInstance 让视图重新渲染 <router-view v-if="!isReloadInstance"/> </el-main> </el-container> </el-container> </template> <script> import Menu from './base-model/menu'; import Header from './base-model/header'; export default { data() { return { isReloadInstance: false }; }, components: { Menu, Header }, mounted() { window.addEventListener('popstate', (e)=>{ this.isReloadInstance = true; this.$nextTick(() => { this.isReloadInstance = false; }); }, false); } };
没刷新是因为只有 query 变了,解决办法是: