[Vuejs]-How to detect the user comes back to a page rather than starts browsing it?

0👍

HISTORY COMPONENT

// component ...
// can error and only serves the purpose of an idea
data() {
  return {
     history: []
  }
},
watch: {
  fullRoute: function(){
      this.history.push(this.fullRoute);
      this.$emit('visited', this.visited);
  }
},
computed: {
 fullRoute: function(){
    return this.$route.fullPath
 },
 visited: function() {
     return this.history.slice(-1).includes(this.fullRoute)
   }
}

the data way

save the information in the browser

// component ...
// can error and only serves the purpose of an idea
computed: {
 gridData: {
   get: function() {
     return JSON.parse(local.storage.gridData) 
   },
   set: function(dataObj){
     local.storage.gridData = JSON.stringify(dataObj)
   }
 }
}
//...

use statemanagement

// component ...
// can error and only serves the purpose of an idea
computed: {
 gridData: {
   get: function() {
     return this.$store.state.gridData || {} 
   },
   set: function(dataObj){
     this.$store.dispatch("saveGrid", gridData)
   }
 }
}
//...

use globals

// component ...
// can error and only serves the purpose of an idea
computed: {
 gridData: {
   get: function() {
     return window.gridData || {} 
   },
   set: function(dataObj){
     window.gridData = dataObj
   }
 }
}

Leave a comment