I have tried to include the window.ethereum.on listener to detect account changes in MetaMask, 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 infinitely 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) {

Thank you. J

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.