1

I'm a begginer vue developer. In vue composition api when you want to create a reactive variable with object source value, you can use both "ref" and "reactive", for example:

const a = ref({ x: 'hi' });
let b = reactive({ x: 'hi' });

// reassignment
a.value.x = 'hello';
Object.assign(b, { x: 'hello' });

note that b.x = 'hello' will remove reactivity from b, so according to my little experience use "ref" instead of "reactive", can satisfy all requirements you need, so the real question for me is this "Why we do not remove "reactive" from all our codes?"

With my little knowledge in "vue" using "reactive" will add more potential mistakes to our codes and I don't understand real benefits of using "reactive" against "ref".

4
  • The best answer stackoverflow.com/a/65262638/2487565 to the topic "ref vs reactive in Vue" Commented Jun 28, 2023 at 13:01
  • @Tolbxela but this does not answer: "Why we do not remove "reactive" from all our codes?" Commented Jul 20, 2023 at 8:45
  • @mohammadasghari 1. reactive ist easier to use and shorter to write without .value, 2. rewriting the whole codebase with about no benefit does not make much sense. Commented Jul 20, 2023 at 9:14
  • @Tolbxela First of all, thank you for your attention. These reasons are absolutely true, but I'm looking for the more technical goals of the Vue development team. Is it reasonable to split the definition of reactive variables only for code style reasons? Commented Jul 22, 2023 at 6:53

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.