有些数据不是原始账本,而是从账本推导出来的结果。
<script setup lang="ts">
import { ref, computed } from 'vue';
const revenue = ref(1200);
const rent = ref(300);
const staffCost = ref(400);
const profit = computed(() => revenue.value - rent.value - staffCost.value);
const shopStatus = computed(() => (profit.value >= 0 ? '盈利' : '亏损'));
</script>
<template>
<p>利润:{{ profit }}</p>
<p>状态:{{ shopStatus }}</p>
</template>如果 ref/reactive 是账本,那么 computed 就是自动电子看板。