Vue.js では、コンポーネントはpropsまたはeventsを使用して相互に通信できます。それはすべて、コンポーネント間の関係に依存します。
この小さな例を見てみましょう:
<template>
<h2>Parent Component</h2>
<child-component></child-component>
</template>
親から子に情報を送信するには、小道具を使用する必要があります。
<template>
<h2>Parent Component</h2>
<child-component :propsName="example"></child-component>
</template>
<script>
export default {
data(){
return{
example: 'Send this variable to the child'
}
}
}
</script>
子から親に情報を送信するには、イベントを使用する必要があります。
子コンポーネント
<script>
...
this.$emit('example', this.variable);
</script>
親コンポーネント
<template>
<h2>Parent Component</h2>
<child-component @example="methodName"></child-component>
</template>
<script>
export default {
methods: {
methodName(variable){
...
}
}
}
</script>
このテーマの詳細については、vue.js のドキュメントを確認してください。これは非常に簡単な紹介です。