inflearn logo
강의

Course

Instructor

Getting Started with Vue.js - Age of Vue.js

this in view instance

질문드려요,

593

daeg874823

2 asked

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

Answer 1

1

captain

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


<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

daeg874823

답변 감사드려요~! :)

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

0

93

2

chrome 확장 devtools 버전 문제

0

81

1

Vue.js not detected가 자꾸 뜹니다

0

83

2

마지막 강의가 안되요

0

57

1

data, computed, watch > Reactivity

0

51

1

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

0

89

1

vue composition api

0

73

1

강의 자료 다운이 될까요?

0

128

1

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

0

586

3

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

0

113

1

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

0

140

1

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

0

236

6

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

0

532

2

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

0

243

1

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

0

310

1

vue3 css 경로 표시 문의

1

231

2

개발자도구 vue탭

0

355

1

화면 코드 보기

1

226

2

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

1

384

2

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

1

886

2

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

1

288

2

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

1

401

2

다음 단계 강의는...?

1

387

2

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

1

277

2