1.在组件中方法使用$forceUpdate方法

 

import Vue from 'vue'
Vue.forceUpdate() // 启动配置

export default {
  data () {},
  methods: {
    handleRefresh() {
      // 写入方法
      this.$forceUpdate()
    }
  }
}

 

 

 

 

2.在组件中绑定key值 

<template>
  <div>
    <demo :key="count"></demo> // 绑定key值
    <button @click="handleRefresh">刷新demo组件</button>
  </div>
</template>
<script>
import demo from "./test.vue";
export default {
  name: "refreshDemo",
  data() {
    return {
      count: 0 
    };
  },
  methods: {
    handleRefresh() {
      this.count += 1 // 更改key值,从而达到刷新组件的效果 当key改变时就是释放原始组件,重新加载新的组件
    }
  }
};
</script>

 

相关文章:

  • 2022-12-23
  • 2021-12-31
  • 2021-07-18
  • 2021-09-01
  • 2022-12-23
  • 2021-06-13
  • 2021-09-09
  • 2021-08-21
猜你喜欢
  • 2022-01-29
  • 2021-07-15
  • 2022-12-23
  • 2021-06-22
  • 2021-11-30
相关资源
相似解决方案