代码记录-开发学习总结3

1. 高亮标记

function markRed (str) {
	if (!str) return ""
	return str
		.replace(/\{/g, '')
		.replace(/\}/g, '')
		.replace('$markName', this.textDesc)
}

或者 动态数据,使用占位符进行匹配

if (this.signText.indexOf('$markName') !== -1) {
	this.signText = this.signText.replace('xxxx', this.textDesc)
}

2. 处理日期20220909为 2022-09-09

function formatDate(date) {
	return `${date.slice(0, 4)} - ${date.slice(4, 6)} - ${date.slice(6,8)}`
}

3. 时间转时间戳,并比较

const time1 = '2022/03/20 10:59:50'
const time2 = '15:33'

function duriingTime (time1, time2) {
	const nowTime = new Date(time1).getTime()
	const endTime = new Date(time1.slice(0,11) + `${time2}:00`).getTime()
	return nowTime <= endTime
}

你可能感兴趣的:(工作总结,学习,javascript,vue.js)