很多项目都碰到过,张三登陆,再开一个tab页,李四登陆。
那么问题来了,张三的页面如果不刷新的话,点增删改查按钮,就会操作李四的数据。
当然后端可以把数据都绑定在登陆用户ID上,但如果项目早期没做关联的话,后面再加,工作量就会很大。
于是想到一个办法前端解决,在首页增加一个隐藏元素,里面内容就是当前登录人的ID,每次数据请求前判断,最后登陆人ID和隐藏元素里面的ID是否一致,如果不一致说明串号了。直接提示用户刷新页面或者关闭之前的tab页。