Browse Source

修复路由缓存

master
wangshuai 2 years ago
parent
commit
628fd9fafc
  1. 74
      src/App.vue

74
src/App.vue

@ -9,35 +9,13 @@
</div>--> </div>-->
<router-view v-slot="{ Component }"> <router-view v-slot="{ Component }">
<component <keep-alive :include="componentNameList">
:is="Component" <component :is="Component" class="x-component" />
v-if=" </keep-alive>
!$route.meta ||
($route.meta &&
($route.meta.notKeepAlive ||
$route.meta.notKeepAlive === undefined))
"
/>
<div
v-if="
!(
!$route.meta ||
($route.meta &&
($route.meta.notKeepAlive ||
$route.meta.notKeepAlive === undefined))
)
"
>
<keep-alive>
<component :is="Component" />
</keep-alive>
</div>
</router-view> </router-view>
<van-sticky position="bottom" class="bg-red"> <x-footer></x-footer>
<x-footer></x-footer>
</van-sticky>
<!-- 未来可能需要封装组件--> <!-- 未来可能需要封装组件-->
</div> </div>
</template> </template>
@ -51,6 +29,7 @@ import { $commonService0, testFun } from "@/app-import";
// console.log(useRouter()); // console.log(useRouter());
const $route = useRoute(); const $route = useRoute();
const router = useRouter(); //
console.log("window.$commonService", window.$commonService); console.log("window.$commonService", window.$commonService);
// 使 $commonService // 使 $commonService
@ -65,11 +44,50 @@ const title = ref("");
// //
// //
onMounted(() => {}); onMounted(() => {});
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
const componentNameList: any = ref([]);
getKeepAlive(router.options.routes as object[]);
// console.log("componentNameList",componentNameList)
function getKeepAlive(routesArr: object[]) {
// console.log(routesArr)
routesArr.forEach((item: any) => {
if (
!item.meta ||
item.meta.notKeepAlive === undefined ||
item.meta.notKeepAlive === false
) {
// console.warn('item',item)
// console.warn('item.component',item.component)
if (item.component) {
componentNameList.value.push(
getComponentName(item.component.toString())
);
}
}
//
if (item.children) {
getKeepAlive(item.children);
}
});
}
//
function getComponentName(url: string) {
const regex = /\/([^\/]+)\.(?=[^\/]*$)/;
const match = regex.exec(url); //
if (match) {
const name = match[1]; //
return name;
}
return "";
}
</script> </script>
<style lang="scss"> <style lang="scss">
@import "src/styles/index"; @import "src/styles/index";
body { body {
min-height: 100vh; min-height: 100vh;
font-size: 16px; font-size: 16px;

Loading…
Cancel
Save