Vue中刷新當前頁面

刷新頁面html

方法一

window.reload()

方法二

this.$router.go(0);

以上兩種方式會出現白屏vue

方法三

不會有閃爍的空白出現
App.vueapp

<template>
  <div id="app">
    <!-- 增長判斷,讓其隱藏 -->
    <router-view v-if="isRouterAlive"/>
  </div>
</template>

<script> export default { name: 'App', // 暴露reload,方便後面組件調用 provide(){ return { reload: this.reload } }, data(){ return { isRouterAlive: true } }, methods:{ // 從新加載方法 reload(){ this.isRouterAlive = false; this.$nextTick(()=>{ this.isRouterAlive = true; }) } } } </script>

子組件調用刷新方法ide

<script> export default { // 獲取APP.vue裏的reload方法 inject: ["reload"], methods: { reloadPage() { // 刷新頁面 this.reload(); } } } </script>

參考
vue項目如何刷新當前頁面this

相關文章
相關標籤/搜索