inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

Vue.js 시작하기 - Age of Vue.js

뷰 인스턴스에서의 this

질문드려요,

598

희영

작성한 질문수 2

1

안녕하세요, 좋은 강의 감사합니다.!

 

$emit, props연습할때에 

 

component 등록 방법을 Vue.component로 변경해서 연습을 해봤는데요, 이벤트가 작동은 하지만 아래와 같은 오류가 나요

어느부분을 확인해봐야하는지 어떻게 고쳐야 하는지 아직 잘 모르겠습니다 ㅜㅜ

답변 부탁드려요..!

 

 

 [오류 내용]

vue.js:634 [Vue warn]: Property or method "addNumber" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.

(found in <Root>)

vue.js:634 [Vue warn]: Property or method "propsnum" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.

(found in <Root>)

 

 

[연습 소스]

 

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <app-header v-on:pass="logText"></app-header>

        <app-content v-on:addnum="addNumEvent" v-bind:propsnum="number">
            <template id="appContentTemp">
                <div>
                    <button v-on:click="addNumber">Click Add</button>
                    <p>{{propsnum}}</p>
                </div>
            </template>
        </app-content>
       
    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script>

        var appheader = {
            template: '<button v-on:click="passEvent">Click Event!</button>',
            methods:{
                passEvent:function(){
                    this.$emit('pass');
                }
            }
        }

        Vue.component('app-content', {
            template : '#appContentTemp',
            props : {
                propsnum:Number,
            },
            methods: {
                addNumber : function(){
                    this.$emit('addnum');
                }
            }
        })

        new Vue({
            el:'#app',
            components:{
                'app-header' : appheader
            },
            data : {
                number : 10
            },
            methods:{
                logText : function(){
                    console.log('hi');
                },
                addNumEvent:function(){
                    this.number += 1;
                    console.log(this.number);
                }
            }
        })

    </script>
</body>
</html>


 

 

 

javascript vuejs

답변 1

1

캡틴판교

안녕하세요, 아래와 같은 코드 패턴은 유효하지 않습니다.


<app-content v-on:addnum="addNumEvent" v-bind:propsnum="number">

<template id="appContentTemp">

<div>

<button v-on:click="addNumber">Click Add</button>

<p>{{propsnum}}</p>

</div>

</template>

</app-content>

컴포넌트 시작 태그와 끝 태그 사이에 코드를 넣는 건 시작하기 강좌 레벨에서 안내해 드리지 않았어요. 추후에 slot 이라는 걸 배우게 되실텐데 그 때 사용하시면 됩니다. 강의에서 안내드린 대로만 사용하시면 됩니다 :)

 

0

희영

답변 감사드려요~! :)

개발자 툴에서 Vue가 표시되지 않는 현상.

0

127

2

chrome 확장 devtools 버전 문제

0

108

1

Vue.js not detected가 자꾸 뜹니다

0

110

2

마지막 강의가 안되요

0

73

1

data, computed, watch > Reactivity

0

58

1

f12누르고 개발자도구에 vue 탭이 안생겨요

0

112

1

vue composition api

0

78

1

강의 자료 다운이 될까요?

0

142

1

개발자 도구에서 뷰탭이 안보여요....

0

628

3

프롭스 데이터 질문입니다.

0

119

1

component.html:11 Uncaught ReferenceError: Vue is not defined at component.html:11:20 (anonymous) @ component.html:11

0

149

1

화면이 안떠요,, 이전 이후 강의는 뜨는데..

0

260

6

크롬 확장 프로그램 vue devtools 설치했는데

0

566

2

코드를 수정하고 브라우저의 Vue로 넘어가면 다운이 됩니다.

0

252

1

버튼을 클릭해도 event가 발생하지 않습니다.

0

320

1

vue3 css 경로 표시 문의

1

242

2

개발자도구 vue탭

0

362

1

화면 코드 보기

1

240

2

App.vue 내용 변경했는데 창이 연결할수없대요ㅜㅜ

1

396

2

html/css/js로 작성된 코드를 vue.js로 일부 전환하고자 이 강의를 듣기 시작했습니다.

1

906

2

{{ num }} 이 <app-content> 아래에 들어가 있을때에는 노출이 안됩니다...

1

296

2

뷰 개발자도구 이벤트 타임라인 어느 부분에서 확인가능한건가요

1

404

2

다음 단계 강의는...?

1

391

2

버튼을 눌러도 data의 값이 변경되지 않습니다

1

287

2