File tree Expand file tree Collapse file tree 5 files changed +64
-6
lines changed Expand file tree Collapse file tree 5 files changed +64
-6
lines changed Original file line number Diff line number Diff line change 1
1
<template >
2
2
<!-- 大组件使用场景:①异步组件方式引入 ②请求动画帧优化白屏 -->
3
- <div class =" big-content-box" >
3
+ <div class =" big-content-1- box" >
4
4
<div class =" item" v-for =" n in 9999" :key =" n" />
5
5
</div >
6
6
</template >
10
10
</script >
11
11
12
12
<style lang="less" scoped>
13
- .big-content-box {
13
+ .big-content-1- box {
14
14
display : flex ;
15
15
flex-wrap : wrap ;
16
16
justify-content : center ;
24
24
background-color : lightpink ;
25
25
}
26
26
}
27
- </style >
27
+ </style >
Original file line number Diff line number Diff line change
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 >
Original file line number Diff line number Diff line change 1
1
<template >
2
2
<div v-for =" n in 999" :key =" n" >
3
- <bigContent v-if =" useDefer(n)" />
3
+ <bigContent1 v-if =" useDefer(n)" />
4
4
</div >
5
5
</template >
6
6
7
7
<script lang="ts" setup>
8
- import bigContent from ' ./../component/big-content.vue' ;
8
+ import bigContent1 from ' ./../component/big-content-1 .vue' ;
9
9
import {defer } from ' ./../toolFunc.ts' ;
10
10
11
11
// 白屏优化
@@ -14,4 +14,4 @@ const useDefer = ((n) => defer(n))();
14
14
15
15
<style lang="less" scoped>
16
16
17
- </style >
17
+ </style >
Original file line number Diff line number Diff line change
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 >
Original file line number Diff line number Diff line change @@ -12,6 +12,10 @@ const router = createRouter({
12
12
path : '/defer' ,
13
13
component : ( ) => import ( './page/defer.vue' ) ,
14
14
} ,
15
+ {
16
+ path : '/sync-async-component' ,
17
+ component : ( ) => import ( './page/sync-async-component.vue' ) ,
18
+ } ,
15
19
{
16
20
path : '/demo' ,
17
21
component : ( ) => import ( './page/demo/index.vue' ) ,
You can’t perform that action at this time.
0 commit comments