0
点赞
收藏
分享

微信扫一扫

uniapp拆分字符串分为两段 ( 用于处理 - 文件名过长中间省略 )

女侠展昭 2022-05-06 阅读 28
export const ellipsisFileName = function(str) {
	const strLength = str.length
	let data = []
	if (strLength > 8) {
		data.push(str.substr(0, strLength - 8))
		data.push(str.substr(-8))
	} else {
		data.push(str)
	}
	return data
}

首先拿到字符串的长度 , 如果长度>8的话 , 把字符串分成两块 , 放到新数组中

举报

相关推荐

0 条评论