我陷入了一个需要你们输入的场景。目前,我正在开发一项功能,即锁定其他管理员的预订。我在预订表中创建了一个字段,当管理员进入预订时,我将 user_id 放置在该字段中,该字段会使用当前管理员 ID 进行更新,并且其他管理员目前确实可以访问该预订。
所以问题是,如果用户关闭该选项卡,其他管理员的预订也会保持锁定状态。
我在 vueJs 中尝试了很多不同的方法,例如beforeunloadMethod. 我使用过 Xhr 方法和 axios 在这种情况下都失败了。我还能做什么来解决这个问题
removeUser () {
var params = JSON.stringify({ locked_by: '' });
let xhr = new XMLHttpRequest()
xhr.open('PUT',Url, true)
xhr.setRequestHeader("Authorization", 'Bearer ' + localStorage.getItem('app_access_token'))
xhr.setRequestHeader("Content-length", params.length);
xhr.setRequestHeader("Content-type", "application/json; charset=utf-8")
xhr.responseType = 'arraybuffer'
xhr.onreadystatechange = function() {//Call a function when the state changes.
if(xhr.readyState == 4 && xhr.status == 200) {
alert(xhr.responseText);
}
}
xhr.send(params);
Run Code Online (Sandbox Code Playgroud)
mounted() {
window.addEventListener('beforeunload', this.removeUser)
Run Code Online (Sandbox Code Playgroud)
还尝试了 beforeunload 事件上的 axios 调用
removeUser (id) { …Run Code Online (Sandbox Code Playgroud)