2018-01-26 05:48:20 +00:00
|
|
|
<cn>
|
|
|
|
#### 自动调整字符大小
|
|
|
|
对于字符型的头像,当字符串较长时,字体大小可以根据头像宽度自动调整。
|
|
|
|
</cn>
|
|
|
|
|
|
|
|
<us>
|
|
|
|
#### Autoset Font Size
|
|
|
|
For letter type Avatar, when the letters are too long to display, the font size can be automatically adjusted according to the width of the Avatar.
|
|
|
|
</us>
|
|
|
|
|
2019-10-09 10:32:23 +00:00
|
|
|
```tpl
|
2018-01-29 01:55:57 +00:00
|
|
|
<template>
|
|
|
|
<div>
|
2019-09-28 12:45:07 +00:00
|
|
|
<a-avatar shape="square" size="large" :style="{backgroundColor: color, verticalAlign: 'middle'}"
|
|
|
|
>{{avatarValue}}</a-avatar
|
|
|
|
>
|
|
|
|
<a-button size="small" :style="{ marginLeft: 16, verticalAlign: 'middle' }" @click="changeValue"
|
|
|
|
>改变</a-button
|
|
|
|
>
|
2018-01-29 01:55:57 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
2018-01-28 12:30:25 +00:00
|
|
|
<script>
|
2019-09-28 12:45:07 +00:00
|
|
|
const UserList = ['U', 'Lucy', 'Tom', 'Edward'];
|
|
|
|
const colorList = ['#f56a00', '#7265e6', '#ffbf00', '#00a2ae'];
|
2018-01-28 12:30:25 +00:00
|
|
|
export default {
|
2019-09-28 12:45:07 +00:00
|
|
|
data() {
|
2018-01-28 12:30:25 +00:00
|
|
|
return {
|
|
|
|
avatarValue: UserList[0],
|
|
|
|
color: colorList[0],
|
2019-09-28 12:45:07 +00:00
|
|
|
};
|
2018-01-28 12:30:25 +00:00
|
|
|
},
|
|
|
|
methods: {
|
2019-09-28 12:45:07 +00:00
|
|
|
changeValue() {
|
|
|
|
const index = UserList.indexOf(this.avatarValue);
|
|
|
|
this.avatarValue = index < UserList.length - 1 ? UserList[index + 1] : UserList[0];
|
|
|
|
this.color = index < colorList.length - 1 ? colorList[index + 1] : colorList[0];
|
2018-01-28 12:30:25 +00:00
|
|
|
},
|
|
|
|
},
|
2019-09-28 12:45:07 +00:00
|
|
|
};
|
2018-01-28 12:30:25 +00:00
|
|
|
</script>
|
2018-01-26 05:48:20 +00:00
|
|
|
```
|