UniApp ページ再レンダリング方法:強制更新と最適化

uniapp内でページを再レンダリングする方法はいくつかあります。

  1. この.$forceUpdate()
this.$forceUpdate();
  1. 表示if
<template>
  <div>
    <ChildComponent v-if="showComponent" />
  </div>
</template>

<script>
export default {
  data() {
    return {
      showComponent: true
    }
  },
  methods: {
    reRenderPage() {
      this.showComponent = false;
      this.$nextTick(() => {
        this.showComponent = true;
      });
    }
  }
}
</script>
  1. 鍵 ( かぎ )
<template>
  <div>
    <ChildComponent :key="componentKey" />
  </div>
</template>

<script>
export default {
  data() {
    return {
      componentKey: 0
    }
  },
  methods: {
    reRenderPage() {
      this.componentKey++;
    }
  }
}
</script>

実際の開発には、適切な方法を選択するために、これらの一般的な再レンダリングページ方法が使用されます。

bannerAds