forked from apache/incubator-weex-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wxc-rich-text-icon.vue
64 lines (61 loc) · 1.37 KB
/
wxc-rich-text-icon.vue
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
64
<!-- CopyRight (C) 2017-2022 Alibaba Group Holding Limited. -->
<!-- Created by Tw93 on 17/07/28. -->
<template>
<image class="wxc-image"
:src="iconSrc"
:aria-hidden="true"
@load="onLoad"
:style="{ width: computedStyle.width, height: computedStyle.height }">
</image>
</template>
<style scoped>
.wxc-image {
width: 90px;
height: 24px;
margin-right: 6px;
}
</style>
<script>
export default {
props: {
iconSrc: {
type: String,
default: ''
},
iconStyle: {
type: Object,
default: () => ({
height: 24
})
}
},
data: () => ({
width: 90
}),
computed: {
computedStyle () {
const { width, iconStyle } = this;
if (iconStyle && iconStyle.width && iconStyle.height) {
return {
width: `${iconStyle.width}px`,
height: `${iconStyle.height}px`
}
} else {
return {
width: `${width}px`,
height: `${iconStyle.height}px`
}
}
}
},
methods: {
onLoad (e) {
if (e.success && e.size && e.size.naturalWidth > 0) {
const width = e.size.naturalWidth;
const height = e.size.naturalHeight;
this.width = width * (this.iconStyle.height / height);
}
}
}
};
</script>