Skip to content

Commit 2692cb9

Browse files
committed
新增按钮组,优化按钮只有图标时跑偏的问题
1 parent a0cb5fb commit 2692cb9

4 files changed

Lines changed: 43 additions & 29 deletions

File tree

‎src/App.vue‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@
1616
<layui-btn type="warm">123</layui-btn>
1717
<layui-btn type="danger" icon="fa fa-bolt" right>123</layui-btn>
1818
<layui-btn type="disabled" size="lg" radius>123</layui-btn>
19+
20+
<layui-btn-group>
21+
<layui-btn type="danger" icon="fa fa-bolt">123</layui-btn>
22+
<layui-btn type="warm">123</layui-btn>
23+
<layui-btn type="danger" icon="fa fa-bolt" right>123</layui-btn>
24+
</layui-btn-group>
25+
26+
<layui-btn-group>
27+
<layui-btn type="danger" icon="fa fa-bolt"></layui-btn>
28+
<layui-btn type="danger" icon="fa fa-bolt" right></layui-btn>
29+
</layui-btn-group>
1930
</div>
2031
</template>
2132

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<template>
2+
<div class="layui-btn-group">
3+
<slot></slot>
4+
</div>
5+
</template>
6+
7+
<script>
8+
export default {
9+
name: 'layui-btn-group'
10+
}
11+
</script>
12+
13+
<style scoped>
14+
i.left{
15+
padding-right: 5px;
16+
}
17+
i.right{
18+
padding-left: 5px;
19+
}
20+
</style>

‎src/components/button/btn.vue‎

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
'layui-btn-radius': radius
88
}]">
99
<i v-if="icon && !right" class="left" :class="icon"></i>
10-
<slot></slot>
11-
<i v-if="icon && right" class="right" :class="icon"></i>
10+
<slot><span style="margin: -2px"></span></slot>
11+
<i v-if="icon && right" class="right" :class="icon"></i>
1212
</div>
1313
</template>
1414

@@ -24,36 +24,17 @@
2424
radius: Boolean,
2525
icon: String,
2626
right: Boolean
27-
},
28-
data: function () {
29-
return {
30-
classList: 'layui-btn '
31-
}
32-
},
33-
mounted: function () {
34-
// ['xs', 'sm', 'md', 'lg', 'xl'].forEach(size => {
35-
// if (this[size] && this[size] < 12) {
36-
// if (this.offset) {
37-
// this.classList += `layui-col-${size + this[size]} `
38-
// this.classList += `layui-col-${size + '-offset' + this.offset} `
39-
// } else {
40-
// this.classList += `layui-col-${size + this[size]} `
41-
// }
42-
// }
43-
// })
44-
// this.classList += `layui-btn-${this.type} `
45-
// if (this.size) {
46-
// this.classList += `layui-btn-${this.size} `
47-
// }
4827
}
4928
}
5029
</script>
5130

5231
<style scoped>
53-
i.left{
54-
padding-right: 5px;
55-
}
5632
i.right{
57-
padding-left: 5px;
33+
padding-left: 4px;
34+
}
35+
36+
i.left{
37+
padding-right: 4px;
5838
}
39+
5940
</style>

‎src/index.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import row from './components/layout/row'
77
import col from './components/layout/col'
88
import container from './components/layout/container'
99

10-
import button from './components/button/btn'
10+
import btn from './components/button/btn'
11+
import btnGroup from './components/button/btn-group'
1112

1213
const layui = {
1314
config: {},
@@ -19,7 +20,8 @@ const layui = {
1920
row,
2021
col,
2122
container,
22-
button
23+
btn,
24+
btnGroup
2325
]
2426
components.forEach(function (component) {
2527
Vue.component(component.name, component)

0 commit comments

Comments
 (0)