S
S
SvizzZzy2021-09-25 15:39:07
Vue.js
SvizzZzy, 2021-09-25 15:39:07

Why does reactivity disappear when objects are merged?

If I write

let object1 = reactive({ });
    let object2 = { test: 123 }
    object1.name = object2.test;

Object reactivity works.
But if you combine an object with another

let object1 = reactive({ });
     let object2 = { test: 123 }

                    object1 = {
                        ...object1,
                        ...object2
                    };

The reactivity is gone.

What could be the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2021-09-25
@SvizzZzy

Because you are replacing a reactive object with a normal one.
Instead of assigning a new object, add the properties of one to another:
Object.assign(object1, object2);
Well, or wrap the new object in reactive, just like the old one.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question