html代码
//eye为睁眼睛 eye-off为闭眼睛
<view>{{ moneyFormat('145444') }}</view>
<u-icon class="font-lg" :name="eyeIconName" @click="eyeIconName == 'eye-off' ? (eyeIconName = 'eye') : (eyeIconName = 'eye-off')"></u-icon>
js代码
data() {
return {
eyeIconName: 'eye-off', //默认为**符号展示
};
},
computed: {
// 格式化金额,等位数转换为星
moneyFormat(e) {
return e => {
if (e || e == 0) {
e = e.toString();
}
if (e && this.eyeIconName == 'eye-off') {
let temp = [];
e.split('').forEach(item => {
temp.push('*');
});
return temp.join('');
} else {
parseFloat(e)
.toFixed(2)
.replace(/(\d)(?=(\d{3})+\.)/g, '$1,');
return e;
}
};
}
},