无头像时,显示名字第一个字

admin2023-12-27 16:15:32

无头像时,显示名字第一个字

如果我们有头像的时候可以调用后端给我们的头像地址,

如果没有可以这样写

<span v-else class="username" > {{name?.charAt(0)}}</span>

显示效果

无头像时,显示名字第一个字

css如下

.username {
           width: 35px;
           height: 35px;
           text-align: center;
           line-height: 35px;
           border-radius: 50%;
           background: #04c9be;
           color: #fff;
           margin-right: 4px;
         }