直接把需要的带过去的参数做成个对象,例如下面的obj
向 toNextPage(url, obj) 传递下游页面及参数
booking(teacherId) {
const obj = {
classdata: this.classdata,
teacherId: teacherId
}
const url = './Booking.html'
this.toNextPage(url, obj)
},
toNextPage(url, obj) {
const objJSON = JSON.stringify(obj)
const objEncode = encodeURI(objJSON)
const href = url + '?obj=' + objEncode
window.location.href = href
},
通过下面这段去获取参数,得到的是一个对象。
getUrlData() {
//获取后台重定向过来的url的参数
const teacherId = this.getQueryVariable('obj')
},
//获取后台通过url传过来的参数,要那个参数就在getQueryVariable("这里填上参数键");
getQueryVariable(variable) {
var query = window.location.search.substring(1)
var vars = query.split('&')
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split('=')
if (pair[0] == variable) {
var objJSON = decodeURI(pair[1])
var obj = JSON.parse(objJSON)
return obj
}
}
return false
},