Compare commits

..

No commits in common. '1d8647af48894264bd780ecf0580e39ba40dbebb' and '9fb82c2a1b9b6fc2cef44f8b95e58a1ac934bfb3' have entirely different histories.

  1. 70
      src/App.vue

70
src/App.vue

@ -9,13 +9,35 @@
</div>--> </div>-->
<router-view v-slot="{ Component }"> <router-view v-slot="{ Component }">
<keep-alive :include="componentNameList"> <component
<component :is="Component" class="x-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> </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>
@ -29,7 +51,6 @@ 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
@ -44,50 +65,11 @@ 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