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) {
...
window.location.reload(true)
})
}
Thank you. J