查找过的资料-防丢失
作者:互联网
数字验证(只能输入数字)
this.formData.imeicode = imeicode.replace(/[^0-9]+/g, "");
表单验证规则
required: true,
message: "请输入设备编码",
trigger: "blur"
min: 6, message: "至少输入6位数字", trigger: "blur"
伪数组转数组
Array.from(dom);
级联选择器
关闭选择器下拉框
this.$refs.refHandle.dropDownVisible = false; //监听值发生变化就关闭它
正则方法(regexp,replace)
testB = RegExp("company_name", "g"),
stringNewData = JSON.stringify(newData);
newStringNewData = newStringNewData.replace(testB, "name");
查找父元素直到满足条件为止
event.target
.closest("div.el-tree-node__content")
.classList.add("node-active");
el-from的回车提交
- 在el-form上加入:
@submit.native.prevent
- 在需要提交的按钮上添加:
native-type="submit"
上面这种方式在el-from的任何input的框都会触发回车提交
@keyup.enter.native="login"
这种方式只在对应的input内按下回车提交
严谨的表单验证通常需要 前端+后端同时验证, 但传统的项目,均只能前后端各做一次检验, 后期规则变更,又得前后端同时修改。
export function printCurrentDate() {
var date = new Date()
var seperator1 = ‘-’
var seperator2 = ‘:’
var month = date.getMonth() + 1
var strDate = date.getDate()
if (month >= 1 && month <= 9) {
month = ‘0’ + month
}
if (strDate >= 0 && strDate <= 9) {
strDate = ‘0’ + strDate
}
var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate +
’ ’ + date.getHours() + seperator2 + date.getMinutes() +
seperator2 + date.getSeconds() + seperator2 + date.getMilliseconds()
}
// 小数整数位数限制
decimalsLength(val, begin, end) {
let reg = new RegExp(^(\\d{0,${begin}})(\\.(\\d{0,${end}}))?$
, ‘g’)
let result = true
if (!reg.test(val)) result = false
return result
},
// 整数位数限制, 不能输入小数
integerLength(val, length) {
let reg = new RegExp(^(\\d{0,${length}})$
)
let result = true
if (!reg.test(val)) result = false
return result
}
doUrlHttp(url) {
if (url.substr(0, 7).toLowerCase() == ‘http://’ || url.substr(0, 8).toLowerCase() == ‘https://’) {
url = url
} else {
url = ‘https://’ + url
}
return url
},
formatDate(source) {
let date = new Date(source)
return date.getFullYear() + ‘-’ + (date.getMonth() + 1) + ‘-’ + date.getDate()
},
dateFormatter(source, format) {
if (!format) {
format = ‘yyyy-MM-dd HH:mm:ss’
}
let date = new Date(source)
let args = {
‘M+’: date.getMonth() + 1,
‘d+’: date.getDate(),
‘H+’: date.getHours(),
‘m+’: date.getMinutes(),
‘s+’: date.getSeconds(),
‘q+’: Math.floor((date.getMonth() + 3) / 3), // quarter
‘S’: date.getMilliseconds()
}
if (/(y+)/.test(format)) {
format = format.replace(RegExp.$1,
(date.getFullYear() + ‘’).substr(4 - RegExp.$1.length))
}
for (let i in args) {
let n = args[i]
if (new RegExp(’(’ + i + ‘)’).test(format)) {
format = format.replace(RegExp.$1,
RegExp.$1.length === 1 ? n : (‘00’ + n).substr((’’ + n).length))
}
}
return format
},
validateFileName(value) {
var pattern = new RegExp(’[#$^&()=|,\[\]./?~!@#¥……&——|【】?]’)
if (pattern.test(value.value)) {
return true
}
return false
},
fileName: {
required: true,
type: ‘string’,
pattern: /^((?![\/
标签:return,strDate,month,var,查找,let,丢失,资料,date 来源: https://blog.csdn.net/m0_46208009/article/details/114536113