私は2つのコンポーネントを持つVueインスタンスを持っています。ユーザーが2番目のコンポーネントのボタンをクリックすると、最初のテンプレートのテンプレートを非表示にします。このスクリプトコードでVueインスタンスからVue.componentにデータを渡すにはどうすればいいですか?
<div id="app">
<mycomp-one :active="active"></mycomp-one>
<mycomp-two></mycomp-two>
</div>
<template id="mycomponent-one">
<div v-show="!active">
<!-- ... --->
</div>
</template>
<template id="mycomponent-two">
<button v-on:click="setActive">Click Me</button>
</template>
:
Vue.component('mycomp-one', {
template: '#mycompnent-one',
// etc...
});
Vue.component('mycomp-two', {
template: '#mycomponent-two',
data: function() {
return {
active: false
};
},
methods: {
setActive: function() {
this.$parent.$options.methods.setActive();
},
},
});
new Vue({
el:'#app',
data:{
active: false
},
methods: {
setActive: function() {
this.active = !this.active;
},
},
});
ボタンがインスタンスへのコンポーネントからの情報を渡すために良い取り組んで、それをクリックすると
私はこのコードを持っています。しかし、ここではデータフローを停止していますが、mycomp-one
コンポーネントは変更を取得しませんでした。どうすれば修正できますか?アクティブな場合はmycomp-one
を非表示にしたい