admin管理员组

文章数量:1025295

If I inspect a computed property in Vue 2.7, I can see that, besides the well-known .value property, there's also .effect. I wasn't able to find any information about it, except that it's deprecated in Vue 3. Does anybody know why it was needed and what its use was? Why has it become deprecated? I'd also appreciate, if somebody shares a link to the page where this property would be documented.

If I inspect a computed property in Vue 2.7, I can see that, besides the well-known .value property, there's also .effect. I wasn't able to find any information about it, except that it's deprecated in Vue 3. Does anybody know why it was needed and what its use was? Why has it become deprecated? I'd also appreciate, if somebody shares a link to the page where this property would be documented.

Share Improve this question asked Nov 18, 2024 at 14:01 LazouskiLazouski 8110 bronze badges 1
  • Looks like it's an old API that was considered when migrating towards the v3. Was probably deprecated in favor of watchEffect. – kissu Commented Nov 18, 2024 at 14:46
Add a comment  | 

1 Answer 1

Reset to default 1

It's an undocumented API for internal purposes that contains a watcher that updates the computed value:

some libs rely on the presence effect for checking computed refs from normal refs, but the implementation doesn't matter

This seems plausible, because in Vue 3 computed and other special kinds of refs have internal properties that make them different from regular refs, but they don't exist in Vue 2 reactivity API.

In Vue itself, it's used for testing.

If I inspect a computed property in Vue 2.7, I can see that, besides the well-known .value property, there's also .effect. I wasn't able to find any information about it, except that it's deprecated in Vue 3. Does anybody know why it was needed and what its use was? Why has it become deprecated? I'd also appreciate, if somebody shares a link to the page where this property would be documented.

If I inspect a computed property in Vue 2.7, I can see that, besides the well-known .value property, there's also .effect. I wasn't able to find any information about it, except that it's deprecated in Vue 3. Does anybody know why it was needed and what its use was? Why has it become deprecated? I'd also appreciate, if somebody shares a link to the page where this property would be documented.

Share Improve this question asked Nov 18, 2024 at 14:01 LazouskiLazouski 8110 bronze badges 1
  • Looks like it's an old API that was considered when migrating towards the v3. Was probably deprecated in favor of watchEffect. – kissu Commented Nov 18, 2024 at 14:46
Add a comment  | 

1 Answer 1

Reset to default 1

It's an undocumented API for internal purposes that contains a watcher that updates the computed value:

some libs rely on the presence effect for checking computed refs from normal refs, but the implementation doesn't matter

This seems plausible, because in Vue 3 computed and other special kinds of refs have internal properties that make them different from regular refs, but they don't exist in Vue 2 reactivity API.

In Vue itself, it's used for testing.

本文标签: vuejsWhat is 39effect39 on Vue computed propertiesStack Overflow