如何在一个页面获取到另一个页面的id

假设我有index这个页面和toindex页面,那如何通过js在toindex这个页面里获取到index这个页面的id?

在index页面跳转到toindex页面链接携带参数,然后https://www.cnblogs.com/raitorei/p/14792575.html%E7%9C%8B%E5%88%AB%E4%BA%BA%E7%9A%84%E6%96%87%E7%AB%A0

或者用正则

getQueryStringValue2: function (url, name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
            var r = url.substr(url.indexOf('?') + 1).match(reg);
            if (r != null) return decodeURIComponent(r[2]); return "";
        }

路由带参跳转、或者 存缓存(a页面存, b页面取)


this.$router.push({
    name: '跳转的页面',
    //要传的值
    query: {
    id: “id”
    }
    });

然后在跳转后的页面里created里面获取

this.$router.push({name : "/页面.vue", query{id : 1}})

一个页面存
localStorage.setItem('keyname',key)
另一个页面取
localStorage.getItem('key')
注意点localStorage在浏览器的隐私模式下不可读取,IE8以上才行,存的值再取出来就是 string类型,其他的自己搜