강의

멘토링

커뮤니티

인프런 커뮤니티 질문&답변

작성자 없음

작성자 정보가 삭제된 글입니다.

Vue.js 제대로 배워볼래?(Vue.js 프로젝트 투입 일주일 전)

부모 컴포넌트에서 자식 컴포넌트의 데이터 값 동기화하기

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'msg')

작성

·

914

0

computed: {
        syncMsg() {
            return this.$refs.childComponent.msg;
        }
  },

위 코드 부분에 에러가 납니다.

child component 및 msg 데이타도 선언되어 있구요.

어떤 문제일까요?

 

답변 1

0

개발자의 품격님의 프로필 이미지
개발자의 품격
지식공유자

<template> 에 삽인한 child component의 ref가 childComponent가 맞나요?

예를들어

<template>

 <child-component ref="childComponent" />

</template>

 

this.$refs에서 접근하기 위해서 ref값이 정확히 맞아야 합니다.

작성자 없음

작성자 정보가 삭제된 글입니다.

질문하기