Browse Source

Merge branch 'master' into dev_230517

dev_230517
zhangzhiyi 2 years ago
parent
commit
1d8647af48
  1. 70
      src/App.vue

70
src/App.vue

@ -9,35 +9,13 @@ @@ -9,35 +9,13 @@
</div>-->
<router-view v-slot="{ Component }">
<component
:is="Component"
v-if="
!$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 :include="componentNameList">
<component :is="Component" class="x-component" />
</keep-alive>
</div>
</router-view>
<van-sticky position="bottom" class="bg-red">
<x-footer></x-footer>
</van-sticky>
<!-- 未来可能需要封装组件-->
</div>
</template>
@ -51,6 +29,7 @@ import { $commonService0, testFun } from "@/app-import"; @@ -51,6 +29,7 @@ import { $commonService0, testFun } from "@/app-import";
// console.log(useRouter());
const $route = useRoute();
const router = useRouter(); //
console.log("window.$commonService", window.$commonService);
// 使 $commonService
@ -65,11 +44,50 @@ const title = ref(""); @@ -65,11 +44,50 @@ const title = ref("");
//
//
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>
<style lang="scss">
@import "src/styles/index";
body {
min-height: 100vh;
font-size: 16px;

Loading…
Cancel
Save