computed 计算属性

独立的 computed 属性

与 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>