获取当前页面url并截取所需字段
let url = window.location.href; // 动态获取当前url // 例: "http://i.cnblogs.com/henanyundian/web/app/#/store?userId=12345678&productId=1234567&shopId=1234567&roleId=1"; let obj = {}; let reg = /[?&][^?&]+=[^?&]+/g; let arr = url.match(reg); if (arr) { arr.forEach(item => { let tempArr = item.substring(1).split("="); let key = decodeURIComponent(tempArr[0]); let val = decodeURIComponent(tempArr[1]); obj[key] = val; }); }, // 截取所需字段并赋值 this.userId = obj.userId; this.productId = obj.productId; this.shopId = obj.shopId; this.roleId = obj.roleId;