Is there any way to 'watch' for localstorage in Vuejs?

前端 未结 6 1856
伪装坚强ぢ
伪装坚强ぢ 2020-12-05 23:20

I\'m attempting to watch for localstorage:

Template:

token - {{token}}

Script:

computed: {
  t         


        
6条回答
  •  情深已故
    2020-12-05 23:50

    you can do it in two ways,

    1. by using vue-ls and then adding the listener on storage keys, with

          Vue.ls.on('token', callback)
      

      or

          this.$ls.on('token', callback)
      
    2. by using storage event listener of DOM:

          document.addEventListener('storage', storageListenerMethod);
      

提交回复
热议问题