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

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

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

在这里插入图片描述

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

你可能感兴趣的:(uni-app,微信小程序,小程序)