欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

vue跳转当前页面不刷新问题

程序员文章站 2022-07-12 19:10:43
...

利用provide 和inject 解决:vue跳转当前页面不刷新问题

App.vue

<template>
  <div id="app">
    <router-view v-if="isRouterAlive" ref="route" />
  </div>
</template>

<script>
export default {
  name: 'App',
  provide() {
    return {
      reload: this.reload
    }
  },
  data() {
    return {
      isRouterAlive: true
    }
  },
  methods: {
    reload() {
      this.isRouterAlive = false
      this.$nextTick(function() {
        this.isRouterAlive = true
      })
    }
  }
}
</script>

要引用的界面

// 第一步:引入
  inject: ['reload'],
// 第二步: 调用
this.reload()
相关标签: vue