IDEA convenient operation and configuration


Three ways to leave the page to realize the monitoring browser:

  created() {
    window.addEventListener('beforeunload', e => {
  destroyed() {
    window.removeEventListener('beforeunload', e => {
  beforeDestroy() {
Methods: { 
     Updatehandler (e) { 
       e = e || window.event 
       if (e) {{ 
         e.returnValue = 'Do you confirm to leave this page-the data you enter may not be saved' 
       this.cancelfunc () 
     async Cancethcunc () { 
         const params = { 
           name: 'AA', 
           _csrf: SessionStorage._csrf 
         await this.Cancelorder (params) 
     async cancelorder (params) { 
       const response = await api.Cancelordrapi (params) // Request background interface 
       console.log ('synchronous request', 


This method is mainly used to meet the needs of statistics and diagnostic codes. These code usually sends data to the web server before uninstalling (UNLOAD) document.


navigator.sendBeacon(url, data);


  • URL indicates the network address to be sent to.


  • Data parameter is the data of ArrayBufferView or Blob, DomString or FormData types to be sent.

return value
When the user agent successfully adds the data to the transmission queue, the SendBeacon () method will return True, otherwise False will be returned.

Since there is an interface, it is simple to implement.

Window.addeventListener ("Beforeunload", (E) => { 
     const data = {name: "Xiaomi"}; 
     window.navigator.sendbeacon ("", json.stringify (data); 

Whether it is refreshing the page or closing the page, the background can receive the request sent from the front end, perfectly implementing the demand.

Method 2 Reference article:


Related Posts

Chengxin University 807 Program Comprehensive Design 2015-2022 Real Questions and Answers [Continuous Update]

UVA Tool website

Right sidebar and return to the top right sidebar code SPONGEBOB

FLINK’s job submission and task scheduling wu

IDEA convenient operation and configuration

Random Posts

[Embedded Linux] Suggestion of learning methods embedded in Linux [Transfer]

pHP related knowledge to learn about it (1)

jasperreport to export PDF with other font MATRIX

C Language’s use of Youth In

30 minutes from zero play to deploy docker+k8s cluster