When user visit the page I want the page to refresh just once.
But if I place location.reload()
in mounted()
. It trigger infinity loop page reload
You just need to come up with a way of conditionally reloading the page to avoid the infinite reload.
One way is to set a value in local storage:
mounted() {
if (localStorage.getItem('reloaded')) {
// The page was just reloaded. Clear the value from local storage
// so that it will reload the next time this page is visited.
localStorage.removeItem('reloaded');
} else {
// Set a flag so that we know not to reload the page twice.
localStorage.setItem('reloaded', '1');
location.reload();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With