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

相关文章
相关标签/搜索