1、加密
1、val.substr(0, 4) + '*'.repeat(val.length - 8) + val.substr(val.length - 4, 4)
2、val.replace(/(\w{4})\w*(\w{4})/, '$1**********$2')
2、当前天前n天(eg:20120101)
for (let i = 0; i < 7; i++) {
const time = new Date(new Date().setDate((new Date().getDate() + i) - 6))
const year = time.getFullYear()
const month = `0${time.getMonth() + 1}`.slice(-2)
const strDate = `0${time.getDate()}`.slice(-2)
temp.push(`${year}\n${month}/${strDate}`)
}
3、字符串限定数量符号隔开
image.png
图示为echarts axisLabel效果
formatter: (value) => {
const getStr = (str) => {
let newStr = ''
if (str.length > 3) {
newStr = str.slice(0, 3) + '\n'
return newStr + getStr(str.slice(3))
} else {
return str
}
}
return getStr(value)
},