let url = 'https://mobyqas.xbotech.com/moby-mall/mobile/index.html?from=singlemessage#/customerActivity/homeActivity?activityKey=Benz&subKey=classA'
//判断url后面带几个?号
if (location.search) {
this.handleUrl(url, 1) //url线上要换成location.href,第二个参数代表有几个问号
return
} else {
this.handleUrl(, 0)//url线上要换成location.href,第二个参数代表有几个问号
}
//需要处理的url方法
handleUrl(url, numData) {
let dataUrl = url.substring(url.indexOf('?') + numData).split('?')
let dataUrls = dataUrl[1].split('&')
let result = {}
for (var i = 0; i < dataUrls.length; i++) {
var temp = dataUrls[i].split('=')
result[temp[0]] = temp[1]
}
console.log(result.activityKey) //输出结果:Benz
tconsole.log(result.subKey) //输出结果:classA
}