In Vue 2, you can use location.reload()
method to refresh the page. You can bind this method to the click event of the button to achieve the effect of refreshing the page when the button is clicked.
Example:
<template>
<div>
<button @click="refreshPage">刷新页面</button>
</div>
</template>
<script>
export default {
methods: {
refreshPage() {
location.reload();
}
}
}
</script>
In the above code, we defined a button, and when the button is clicked, refreshPage
the method will be called. This method is used internally location.reload()
to refresh the page. This method reloads the entire page and clears all state for the current page.