uniapp 微信小程序 姓名脱敏 substring报错问题:Cannot read property ‘substring‘ of undefined

效果图:
刘德华----------刘*
在这里插入图片描述

加v-if判断是因为如果是后台数据返回的字段,如果不加判断,substring的时候有可能数据还没渲染完,会报错

在这里插入图片描述

<text v-if="userName">{
    
    {
    
    userName.substring(0, 1) + '*'}}</text>

猜你喜欢

转载自blog.csdn.net/maoge_666/article/details/131847434
今日推荐