2017-12-28 37 views
0

아래와 같이 부모 컴포넌트 템플릿에 버튼이 있습니다.vue.js에서 부모 템플릿의 함수를 호출하십시오.

<template> 
     <div class="data_table"> 
      <button class="mini ui button" @click="show">     
     </div> 
    </template> 

show()

<script> 
    export default { 
     data: 
      function() { 
       return { 
        value: this.active1 
       } 
      }, 
     props: { 
      active1: true 
     },   
     methods: { 
      show() { 
       this.active1 = true 
      } 
     }, 
    } 
</script> 

가 어떻게 show() 기능 있음을 호출 할 수 있습니다 아래처럼 아이 컴퍼넌트에 보관?

나는 vue-cli을 사용하고 있습니다.

감사

+1

당신은 버튼 구성 요소입니다 의미합니까? – samayo

+0

답장을 보내 주셔서 감사합니다 @ samayo. 아니요, 해당 버튼은 다른 HTML 콘텐츠와 함께 부모 템플릿 안에 있습니다. 감사합니다 –

+1

아마 더 많은 예제를 추가해야한다고 생각합니다 – samayo

답변

0

하위 구성 요소

<template> 
<div class="data_table"> 
    <button class="mini ui button" @click="show">     
</div> 
</template> 


data: => ({ 
value: this.active1 
}), 
props: { 
active1: { 
    type: Boolean 
} 
}, 
methods: { 
    show() { 
    this.$emit('someEventName') 
    } 
} 

부모 구성 요소

<template> 
    <child-component 
     :active1="booleanValue" 
     @someEventName="show" 
    /> 
</template> 


data: => ({ 
booleanValue: false 
}), 
method: { 
show() { 
    this.booleanValue = true 
} 
}