Gyh's blog

vuePress-theme-reco gyh    2022
Gyh's blog Gyh's blog

Choose mode

  • dark
  • auto
  • light
Home
Category
  • Algorithm
  • CSS
  • JavaScript
  • Others
  • Server
  • Utils
  • Article
  • Note
  • Git
  • Npm
  • Standard
  • Summary
Tag
Timeline
About
GitHub
author-avatar

gyh

91

Article

11

Tag

Home
Category
  • Algorithm
  • CSS
  • JavaScript
  • Others
  • Server
  • Utils
  • Article
  • Note
  • Git
  • Npm
  • Standard
  • Summary
Tag
Timeline
About
GitHub

VUE 实现局部刷新

vuePress-theme-reco gyh    2022

VUE 实现局部刷新

gyh 2018-09-09

我们可以利用 Vue 里面的 provide+inject 组合

  • 首先需要修改 App.vue

    //App.vue
    <template>
      <div id="app">
        <div>
          <router-view v-if="alive" />
        </div>
      </div>
    </template>
    <script>
    export default {
      name: 'App',
      provide() {
        return {
          reload: this.reload
        }
      },
      data() {
        return {
          alive: true
        }
      },
      methods: {
        reload() {
          this.alive= false
          this.$nextTick(() => {
            this.alive = true
          })
        }
      }
    }
    </script>
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
  • 其次到需要刷新的页面进行引用

    使用 inject 导入引用 reload

     inject: ['reload'],
     this.reload()
    
    1
    2
Edit on GitHub~
LastUpdated: 5/17/2022, 8:59:22 AM