1、必须包含小数点
let regDis = /^(?=0\.[1-9]|[1-9]\.\d).{3}$|^([2-9])$/
2、非必须包含小数点
let regDis = /^[0-9]{1}(\.[0-9])?$/
3、判断H5是否在小程序webview打开
<script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.3.2.js"></script> <script> var ua = navigator.userAgent.toLowerCase(); if(ua.match(/MicroMessenger/i)=="micromessenger") { //ios的ua中无miniProgram,但都有MicroMessenger(表示是微信浏览器) wx.miniProgram.getEnv((res)=>{ if (res.miniprogram) { alert("在小程序里"); } else { alert("不在小程序里"); } }) }else{ alert('不在微信里'); } </script>
4、window.open()跳转被拦截!
通过异步请求获取跳转链接后再进行window.open跳转会被浏览器拦截。
解决方案
export default { data() { return { jumpUrl: '', newWin: null // 新窗口的引用 } }, watch: { url(newVal, oldVal) { if(newVal && this.newWin) { this.newWin.sessionStorage.clear() this.newWin.location.href = newVal; this.jumpUrl = ''; this.newWin = null; } } }, methods: { clickHandle() { let _this = this; // 先打开一个空的新窗口,再请求 this.newWin = window.open(); api.get('xxx', params).then(response => { let data = response.data; if(data.code === 0 ) { _this.jumpUrl = data.data.url || ''; } }); } } }
6、数组对象去重
export function deteleObject(obj) { var uniques = []; var stringify = {}; for (var i = 0; i < obj.length; i++) { var keys = Object.keys(obj[i]); keys.sort(function(a, b) { return (Number(a) - Number(b)); }); var str = ''; for (var j = 0; j < keys.length; j++) { str += JSON.stringify(keys[j]); str += JSON.stringify(obj[i][keys[j]]); } if (!stringify.hasOwnProperty(str)) { uniques.push(obj[i]); stringify[str] = true; } } uniques = uniques; return uniques; }
deteleObject(obj) { var hash = {}; obj = obj.reduce(function(item, next) { hash[next.openid] ? '' : hash[next.openid] = true && item.push(next); return item }, []) return obj },