与 ref 和 watch 类似,也可以使用从 vue 的 computed 函数在 Vue 组件外部创建计算属性。
import { ref, computed } from 'vue'
<template>
<div>
<button @click="count++">点击计数 : {{count}}</button>
</div>
<div>
{{twiceTheCounter}}
</div>
</template>
<script setup>
import {ref, reactive, computed} from "Vue";
const count = ref(0);
const twiceTheCounter = computed(() => {return count.value * 2;})
</script>