<template>
	<u-avatar size="46" :src="userInfo.avatar" :text="text"></u-avatar>
</template>

<script>
export default {
	name: 'userAvatar',
	computed: {
		userInfo() {
			return this.$store.state.user.userInfo || {};
		},
		text() {
			const { avatar, userName = '' } = this.userInfo;
			return avatar ? undefined : userName.charAt(0);
		},
	},
	created() {
		if (Object.keys(this.userInfo).length === 0) {
			// 如果没有用户信息则获取
			this.$store.dispatch('user/GetInfo'); // 获取用户信息
		}
	},
};
</script>

<style scoped></style>
