index.js
/*** 计算两个日期范围内包含的天数* @param {string} time* @param {string} time* @returns {number}*/
export function dateDiff(first, second) {const firstDate = new Date(first)const secondDate = new Date(second)const diff = Math.abs(firstDate.getTime() - secondDate.getTime())const result = parseInt(diff / (1000 * 60 * 60 * 24))return result ? result + 1 : 0
}
页面使用
<div class="left">通话日期</div><div class="right"><el-date-pickerv-model="checkParams.conversationDate"size="small"type="daterange"value-format="yyyy-MM-dd"start-placeholder="开始时间"end-placeholder="结束时间"class="sale-control":clearable="false"/></div>
import { dateDiff} from '@/utils'const conversationDateDiff = dateDiff(this.checkParams.conversationDate[0], this.checkParams.conversationDate[1])if (conversationDateDiff > 31) {this.$message.error('查询条件中通话日期查询区间不能大于1个月!')return}