2017-09-21 3 views

답변

0

이를 위해 당신은 단순히 글로벌 버스를 사용할 수 있으며 그에게 이벤트를 방출 :

여기
var bus = new Vue(); 

Vue.component('comp-a', { 
    template: `<div><button @click="emitFoo">Click Me</button></div>`, 
    methods: { 
    emitFoo() { 
     bus.$emit('foo'); 
    } 
    } 
}); 

Vue.component('comp-b', { 
    template: `<div>{{msg}}</div>`, 
    created() { 
    bus.$on('foo',() => { 
     this.msg = "Got Foo!"; 
    }) 
    }, 
    data() { 
    return { 
     msg: 'comp-b' 
    } 
    } 
}); 

가 JSFiddle입니다 : https://jsfiddle.net/6ekomf2c/

당신은 당신이 봐야 더 복잡한 작업을 수행 할 필요가있는 경우 Vuex

0

@craig_h가 정확한지, 또는 당신은 같은 $의 심판을 사용할 수 있습니다

<parent-element> 
    <sibling-a @onClickButton="changeCall"></sibling-a> 
    <sibling-b ref="b"></sibling-b> 
</parent-element> 
siblingA에서

methods: { 
    changeCall() { 
     this.$refs.b.dataChange = 'changed'; 
    } 
    } 

:

Vue.component('sibling-a', { 
    template: `<div><button @click="clickMe">Click Me</button></div>`, 
    methods: { 
    clickMe() { 
     this.$emit('onClickButton'); 
    } 
    } 
}); 

siblingB 물 :

Vue.component('sibling-b', { 
    template: `<div>{{dataChange}}</div>`, 
    data() { 
    return { 
     dataChange: 'no change' 
    } 
    } 
}); 
상위 방법에서

관련 문제