Vue实现页面的局部刷新

2020-01-26  本文已影响0人  王玉伟的伟

在 app.vue 组件里面的编写

<template>
  <div id="app">
    <!-- 路由占位符 -->
    <router-view v-if="isRouterAlive"></router-view>
  </div>
</template>

<script>

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

<style lang="less" scoped>

</style>

在需要用到的组件里面引用

export default {
  inject: ['reload'],
  // 监听对话框的确定按钮
    editCategoryDialogConfirm () {
      let _this = this
        _this.reload()
      })
    }
}
上一篇 下一篇

猜你喜欢

热点阅读