Vue

梗概

  • 定义:未被trackVue computed
    • 这里的track不包含其他懒computed的track
  • 作用:只有访问该懒computed时,才回去计算新的computed

实例

<template>
  <div id="text"></div>
  <button @click="a++">add a</button>
  <button @click="b;">access b</button>
</template>
<script setup lang="ts">
import { computed, onMounted, ref, watch } from "vue";
let a = ref(1);
let b = computed(() => {
  console.log("compute b");
  return a.value + 1;
});
watch(a, () => {
  console.log("watched a");
});
</script>
<style></style>
  • 当点击add a按钮时,只显示watched a,除非点击access b按钮