图片路径转码、获取当前时间、返回url指定参数、短信验证60s

it2026-01-11  9

图片路径转码

replaceStr(str) { str = str.replace(/%3A/g, ":"); str = str.replace(/%2F/g, "/"); str = str.replace(/%3F/g, "?"); str = str.replace(/%3D/g, "="); str = str.replace(/%26/g, "&"); str = str.replace(/%2B/g, "+"); str = str.replace(/%20/g, " "); str = str.replace(/%23/g, "#"); return str; }

获取当前时间

getTime(){ var date = new Date(); var seperator1 = "-"; var seperator2 = ":"; //以下代码依次是获取当前时间的年月日时分秒 var year = date.getFullYear(); var month = date.getMonth() + 1; var strDate = date.getDate(); var minute = date.getMinutes(); var hour = date.getHours(); var second = date.getSeconds(); //固定时间格式 if (month >= 1 && month <= 9) { month = "0" + month; } if (strDate >= 0 && strDate <= 9) { strDate = "0" + strDate; } if (hour >= 0 && hour <= 9) { hour = "0" + hour; } if (minute >= 0 && minute <= 9) { minute = "0" + minute; } if (second >= 0 && second <= 9) { second = "0" + second; } var currentdate = month + seperator1 + strDate + " " +hour + seperator2 + minute; this.time=currentdate return currentdate; }

返回url指定参数

GetUrlParam(name) { //获取url指定参数 var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象 var r = window.location.search.substr(1).match(reg); //匹配目标参数 if (r != null) return unescape(r[2]); return null; //返回参数值 }

//短信验证60s

count: '', timer: null, codeShow:true, getCode(){ const TIME_COUNT = 60; if (!this.timer) { this.count = TIME_COUNT; this.codeShow = false; this.timer = setInterval(() => { if (this.count > 0 && this.count <= TIME_COUNT) { this.count--; } else { this.codeShow = true; clearInterval(this.timer); this.timer = null; } }, 1000) } }//发送短信验证 sendyz(){ this.tel = this.$refs.tel.value; const reg = /^1([38]\d|5[0-35-9]|7[3678])\d{8}$/; if (this.tel == '' || this.tel <= 10 || !reg.test(this.tel)) { this.hint = '请填写正确手机号' } else { this.getCode(); this.hint='' this.$axios({ method: '', url: '', params: {sjh:this.tel} }).then((res) => {console.log(res);}) .catch(err => {console.log(err)}) } }
最新回复(0)