Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5cc9ef1

Browse files
author
chenxin
committed
同步/异步组件测试
1 parent ce220a2 commit 5cc9ef1

File tree

5 files changed

+64
-6
lines changed

5 files changed

+64
-6
lines changed

src/component/big-content.vue renamed to src/component/big-content-1.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<!-- 大组件使用场景:①异步组件方式引入 ②请求动画帧优化白屏 -->
3-
<div class="big-content-box">
3+
<div class="big-content-1-box">
44
<div class="item" v-for="n in 9999" :key="n"/>
55
</div>
66
</template>
@@ -10,7 +10,7 @@
1010
</script>
1111

1212
<style lang="less" scoped>
13-
.big-content-box {
13+
.big-content-1-box {
1414
display: flex;
1515
flex-wrap: wrap;
1616
justify-content: center;
@@ -24,4 +24,4 @@
2424
background-color: lightpink;
2525
}
2626
}
27-
</style>
27+
</style>

src/component/big-content-2.vue

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<template>
2+
<!-- 大组件使用场景:①异步组件方式引入 ②请求动画帧优化白屏 -->
3+
<div class="big-content-2-box">
4+
<div class="item" v-for="n in 9999" :key="n"/>
5+
</div>
6+
</template>
7+
8+
<script lang="ts" setup>
9+
10+
</script>
11+
12+
<style lang="less" scoped>
13+
.big-content-2-box {
14+
display: flex;
15+
flex-wrap: wrap;
16+
justify-content: center;
17+
margin: 10px 0;
18+
border: 2px solid dodgerblue;
19+
20+
.item {
21+
width: 4px;
22+
height: 4px;
23+
margin: 0.1em;
24+
background-color: lightblue;
25+
}
26+
}
27+
</style>

src/page/defer.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<template>
22
<div v-for="n in 999" :key="n">
3-
<bigContent v-if="useDefer(n)"/>
3+
<bigContent1 v-if="useDefer(n)"/>
44
</div>
55
</template>
66

77
<script lang="ts" setup>
8-
import bigContent from './../component/big-content.vue';
8+
import bigContent1 from './../component/big-content-1.vue';
99
import {defer} from './../toolFunc.ts';
1010
1111
//白屏优化
@@ -14,4 +14,4 @@ const useDefer = ((n) => defer(n))();
1414

1515
<style lang="less" scoped>
1616
17-
</style>
17+
</style>

src/page/sync-async-component.vue

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<template>
2+
<div style="display: flex">
3+
<div style="flex: 1;margin: 0 10px">
4+
<el-divider>同步组件</el-divider>
5+
<el-button type="primary" @click="showBigContentSync = !showBigContentSync">change</el-button>
6+
<bigContentSync v-if="showBigContentSync"/>
7+
</div>
8+
<div style="flex: 1;margin: 0 10px">
9+
<el-divider>异步组件</el-divider>
10+
<el-button type="primary" @click="showBigContentAsync = !showBigContentAsync">change</el-button>
11+
<bigContentAsync v-if="showBigContentAsync"/>
12+
</div>
13+
</div>
14+
</template>
15+
16+
<script lang="ts" setup>
17+
import {ref, defineAsyncComponent} from 'vue';
18+
import bigContentSync from './../component/big-content-1.vue'; // 同步组件
19+
const bigContentAsync = defineAsyncComponent(() => import('./../component/big-content-2.vue'));// 异步组件
20+
21+
const showBigContentSync = ref(false);
22+
const showBigContentAsync = ref(false);
23+
</script>
24+
25+
<style lang="less" scoped>
26+
27+
</style>

src/router.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ const router = createRouter({
1212
path: '/defer',
1313
component: () => import('./page/defer.vue'),
1414
},
15+
{
16+
path: '/sync-async-component',
17+
component: () => import('./page/sync-async-component.vue'),
18+
},
1519
{
1620
path: '/demo',
1721
component: () => import('./page/demo/index.vue'),

0 commit comments

Comments
 (0)