1
1
<template >
2
2
<el-scrollbar >
3
3
<div class =" demo" >
4
- <div class =" list" >
5
- <div
6
- class =" item"
7
- :style =" {
8
- width: `calc(${100 / cols}% - 10px)`
9
- }"
10
- :ref =" `col-${index + 1}`"
11
- v-for =" (item, index) in layout"
4
+ <el-row :gutter =" 10" >
5
+ <el-col
6
+ v-for =" (item, index) in list"
12
7
:key =" index"
8
+ :xs =" 24"
9
+ :sm =" 12"
10
+ :md =" 8"
11
+ :lg =" 6"
13
12
>
14
- <transition-group name =" fade" >
15
- <component
16
- :ref =" item2"
17
- :is =" item2"
18
- :key =" item2 + index2"
19
- v-for =" (item2, index2) in item"
20
- ></component >
21
- </transition-group >
22
- </div >
23
- </div >
13
+ <component :is =" item" ></component >
14
+ </el-col >
15
+ </el-row >
24
16
</div >
25
17
</el-scrollbar >
26
18
</template >
@@ -58,93 +50,16 @@ export default {
58
50
" b-cl-context-menu" ,
59
51
" b-error-page" ,
60
52
" b-cl-editor-quill"
61
- ],
62
- cols: 4 ,
63
- layout: [[], [], [], []]
53
+ ]
64
54
};
65
- },
66
-
67
- mounted () {
68
- const width = document .body .clientWidth ;
69
-
70
- if (width < 768 ) {
71
- this .cols = 1 ;
72
- } else if (width < 1000 ) {
73
- this .cols = 2 ;
74
- } else if (width < 1500 ) {
75
- this .cols = 3 ;
76
- } else {
77
- this .cols = 4 ;
78
- }
79
-
80
- this .append ();
81
- },
82
-
83
- methods: {
84
- getHeight (name ) {
85
- return this .$refs [name][0 ].offsetHeight ;
86
- },
87
-
88
- selectCol () {
89
- let arr = new Array (this .cols ).fill (1 );
90
-
91
- for (let i = 0 ; i < this .cols ; i++ ) {
92
- arr[i] = this .getHeight (` col-${ i + 1 } ` );
93
- }
94
-
95
- let min = Math .min .apply (this , arr);
96
-
97
- return arr .indexOf (min);
98
- },
99
-
100
- append (index = 0 ) {
101
- const i = this .selectCol ();
102
- const item = this .list [index];
103
-
104
- if (! item) {
105
- return false ;
106
- }
107
-
108
- this .layout [i].push (item);
109
-
110
- this .$nextTick (() => {
111
- setTimeout (() => {
112
- this .append (index + 1 );
113
- }, 100 );
114
- });
115
- }
116
55
}
117
56
};
118
57
</script >
119
58
120
59
<style lang="scss">
121
- .fade-enter-active ,
122
- .fade-leave-active {
123
- transition : all 0.5s ease ;
124
- }
125
-
126
- .fade-enter ,
127
- .fade-leave-active {
128
- opacity : 0 ;
129
- }
130
-
131
60
.demo {
132
61
overflow : hidden ;
133
62
134
- .list {
135
- margin : 0 -5px ;
136
- }
137
-
138
- .item {
139
- width : calc (25% - 10px );
140
- margin : 0 5px ;
141
- float : left ;
142
-
143
- & :last-child {
144
- margin-right : 0 ;
145
- }
146
- }
147
-
148
63
.scope {
149
64
background-color : #fff ;
150
65
border-radius : 3px ;
@@ -170,6 +85,8 @@ export default {
170
85
171
86
.c {
172
87
padding : 10px ;
88
+ height : 50px ;
89
+ box-sizing : border-box ;
173
90
174
91
& ._svg {
175
92
.icon-svg {
0 commit comments