js获取上一个页面带过来的id方法之一
前提:
在viewspot.html页面中通过
<a :href="'updateviewspot.html?id='+place.sid">修改</a>
带id跳转到updatespot.html页面
在updatespot.html页面获取到id
步骤和解释:
1.在updatespot,html中的csript标签里写
<script>
let id = location.href.substring(location.href.indexOf("=")+1);
</script>
2.在substring中先用location.href获取该地址,再用indexOf方法获取地址中 = 号所在的位置的后一个位置
3.用substring方法截取刚刚位置后的所有(substtring(star,end)里可以有两个参数代表截取字符的起始位置,只写一个参数代表截取从那个参数后面的所有),就能够拿到id了