lilishop-uniapp/uview-ui/libs/function/addUnit.js

8 lines
381 B
JavaScript
Raw Normal View History

2021-05-13 11:03:32 +08:00
import validation from './test.js';
// 添加单位如果有rpx%px等单位结尾或者值为auto直接返回否则加上rpx单位结尾
export default function addUnit(value = 'auto', unit = 'rpx') {
value = String(value);
// 用uView内置验证规则中的number判断是否为数值
return validation.number(value) ? `${value}${unit}` : value;
}