梗概
- 定义:未被track的Vue computed
- 这里的track不包含其他懒computed的track
- 作用:只有访问该懒computed时,才回去计算新的computed
- [base::依赖收集]
实例
<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按钮