firebase - 在页面卸载之前提出请求
问题描述
我正在开发单页 vue 应用程序。
在这个应用程序中,我使用 firebase 实时数据库来存储用户。
我只想在页面卸载之前更新用户在 firebase 上的“isOnline”状态。
所以,我想发出http请求。可能吗 ?
下面的代码不能解决问题......
new Vue({
created(){
window.onbeforeunload = function() {
apiservice.update(this.user);
return null
};
},
}
解决方案
你可以试试 :
new Vue({
created () {
window.addEventListener('beforeunload', this.updateUser)
},
methods: {
updateUser () {
console.log('updating user')
}
}
})
推荐阅读
- security - 如何找到生成的openssl密钥的页眉和页脚以及公钥的值是什么
- angular - 防止 ngFor 中子组件的数据绑定
- kotlin - 在 Vert.x 的 service-proxy 中使用 Kotlin 的数据类
- python - 如何在年度时间序列中获得所有年份的 7 月?(Jupyter 笔记本)
- java - 如何在 JPanel 的所有组件上绘制一些东西
- r - 错误:stat_count() 不得与任何美学一起使用
- android - 如何在我的 android 应用程序中完全隐藏 ui
- android - 哪个框架可用于在 Android 上绘制复杂的交互式 UI 层次结构?(就像 iOS 上的 CoreAnimation)
- computer-science - 如何对 5 个正整数进行排序?
- amazon-web-services - AWS Educate 账户下的 AWS CodeDeploy