Calling a Listener and location.reload() Method within the mounted Method

135 views Asked by At

I have tried to include a listener (window.ethereum.on) for an event in my mounted () {} method. When the listener is triggered, it itself triggers the location.reload() method.

When including this listener and location.reload() method in my mounted () {} method, it is triggered in an infinite loop, the location.reload() method being re-triggered at every reload. However, if I include the listener outside the mounted method, it is never called. Where should the listener be defined?

 mounted () {
   ...
   window.ethereum.on('accountsChanged', function (accounts) {
     ...
     window.location.reload(true)
   })
 }
0

There are 0 answers