햇갈렷던것.. 반응성관련
| topics | 200-프론트개발 202 Vue.js |
| types | 에러해결 학습 |
| tags |
Vue 반응성 관련 햇갈렸던 것들
참고 자료
https://junglast.com/blog/vue3-props-reactive
const a = reactive({
count: 0,
someObject: {
someProperty: 'someValue',
otherObject: {
otherProperty: 'otherValue'
}
}
});
const b = ref({
count: 0,
someObject: {
someProperty: 'someValue',
otherObject: {
otherProperty: 'otherValue'
}
}
});
const c = toRefs(a);
const d = reactive(a);

=> toRefs는 deep하게 반응성이 유지되지않는다.
걍 toRef쓸바에는 reactive나 머그런거롤 덮어씌우자.
const a = reactive({
count: 0,
someObject: {
someProperty: 'someValue',
otherObject: {
otherProperty: 'otherValue'
}
}
});
const b = ref(a);
const c = {...a};
const d = reactive(a);

spread구문을 사용하여 복사했을때
예상대로 count는 반응성이 유지되지않고 나머지는 유지되었다.
count는 원자형이라 주소를 새로할당받는데 object는기존주소를 써서그렇다 ㅇㅇ