ref() 和 watch() 组合是否等同于 Vue 3 中的 computed()?

Is ref() & watch() combination equivalent to computed() in Vue 3?

我有一个反应对象

team

它有一个 属性

players

我还想使 players 具有反应性(通过从自定义挂钩导出它以便于使用)。

这两段代码等价吗?

(我想他们不是,但我想知道以另一种方式使用一个的陷阱)

const players = computed(() => team.value.players);
const players = ref(team.value.players);

watch(team, () => players.value = team.value.players);

我应该使用哪一个?有很大的不同吗(优化?) v-model 的用法如何?

建议将计算 属性 与 getter/setter 结合使用,以便能够将其绑定到 v-model :

const players = computed({
 get() => team.value.players,
 set(newVal){
 
 }
});