# 一.命令输入(按钮)
前言 --> 按钮组件特点
按钮组件组成:
它的主要功能包括:
# 1.目录结构
├── button
│ ├── src
│ │ ├── button-group.vue
│ │ └── button.vue
│ └── index.js
1
2
3
4
5
2
3
4
5
# 2.组件封装
# 2.1 button
<template>
<div class="vue-button" :class="type" v-bind="$attrs" v-on="$listeners">
<slot></slot>
</div>
</template>
<script>
export default {
name: "VueButton",
props: {
type: {
type: String,
default: "default",
},
},
};
</script>
<style lang="scss" scoped>
.vue-button {
display: inline-block;
padding: 5px 20px;
border: 1px solid gray;
border-radius: 4px;
cursor: pointer;
}
.default {
background-color: #FFFFFF;
}
.primary {
background-color: #409eff;
}
.success {
background-color: #67C23A;
}
.warning {
background-color: #E6A23C;
}
.danger {
background-color: #F56C6C;
}
</style>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# 2.2 button-group
<template>
<div :class="{ 'button-group': justify === 'center', 'global-group': true }">
<el-row type="flex" class="row-bg" :justify="justify">
<el-col><slot></slot></el-col>
</el-row>
</div>
</template>
<script>
export default {
name: "VueButtonGroup",
props: {
justify: {
type: String,
default: "center",
},
},
data() {
return {
addModalFlag: false,
};
},
};
</script>
<style>
.button-group {
text-align: center;
}
.global-group {
margin: 10px 0;
}
</style>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# 3.使用案例
# 3.1 button
# 3.1.1
刷新
全屏/自适应
# 3.2 button-group
# 3.2.1
刷新
全屏/自适应
# 3.2.2
刷新
全屏/自适应
总结
通过对前端组件的分析,需要重点关注组件中易变性对组件封装的影响,它会对组件的可复用性、可扩展性产生很大影响