f-icon.vue
1.34 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<template>
<view class="u-icon u-flex" @tap="clickHandler">
<view :class="[customPrefix,customPrefix+'-'+name]" :style="{color:color,fontSize:size+'rpx'}"></view>
</view>
</template>
<script>
export default {
name: 'f-icon',
props: {
// 图标类名
name: {
type: String,
default: ''
},
// 图标颜色,可接受主题色
color: {
type: String,
default: ''
},
// 字体大小,单位rpx
size: {
type: [Number, String],
default: 'inherit'
},
// 自定义扩展前缀,方便用户扩展自己的图标库
customPrefix: {
type: String,
default: 'custom-icon'
},
},
data() {
return {
};
},
methods: {
clickHandler(e) {
this.$emit('click', this.index)
// 是否阻止事件冒泡
this.stop && this.preventEvent(e)
},
// 阻止事件冒泡
preventEvent(e) {
e && typeof (e.stopPropagation) === 'function' && e.stopPropagation()
},
}
};
</script>
<style lang="scss" scoped>
.u-flex{
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
flex-direction: row;
align-items: center;
}
.u-icon {
display: inline-flex;
justify-content: center;
}
</style>