js window.location.href切换页面并传值及接受值
原创传值通过?在url传递上拼接值。以下分别是单参数传递和多参数传递:
window.location.href = "/static/test.html?type=" + this.selected
window.location.href = "/static/test.html?type=" + this.selected + &value= + val;
接收值:
//获取地址栏参数,name:参数名称
        function getUrlParms (name) {
            let url = window.location.href;//获取请求的完整性。url
            let tstr = url.substring(url.indexOf(?) + 1).split(&);//先截取url的?以下参数部分,根据&拆分为参数数组
            let result = {};
            tstr.forEach((item) => {
                let res = item.split(=);//res为type,my-component1.vue。  res[0]为type,res[1为]my-component1.vue
                result[res[0]] = res[1];//构造为键值对形式 res[0]为键,res[1]为值 例:type: "my-component1.vue" 
            })
            return result[name];//按关键字排序的值
        }
    var type = getUrlParms("type");//调用函数								版权声明
所有资源都来源于爬虫采集,如有侵权请联系我们,我们将立即删除
itfan123



