부모를 공유하는 경우 이와 같은 작업을 수행 할 수 있지만 태그가 결합되므로 권장하지 않습니다. 간단한 태그 통신에 대한
<parent>
<tag-a></tag-a>
<tag-b></tag-b>
</parent>
<tag-a>
<script>
this.o = 'Hi bro'
</script>
</tag-a>
<tag-b>
<span>{this.parent.tags.tag-a.o}</span>
</tag-b>
더 많은 정보는 : http://vitomd.com/blog/coding/tag-communication-in-riot-js-part-1/
더 좋은 방법은 관찰 패턴을 사용하여 통신하는 것입니다.
먼저 당신은 당신이 글로벌 폭동 변수에 저장소를 추가 태그를 장착하기 전에 index.html을에서
//Store.js
var Store = function(){
riot.observable(this)
}
그런 다음 store.js을 만드는, 그래서 어떤 태그에서 액세스 할 수
<script type="text/javascript">
riot.store = new Store()
riot.mount('* ')
</script>
그런 다음 태그-A에 당신은
send_info() {
riot.store.trigger('send_to_b', 'Hello')
}
그리고 태그-B의
받은 정보를 원하시면에게 혼란을 보내도록 트리거 할 수 있습니다 나이
riot.store.on('send_to_b', function(greeting) {
self.hi = greeting
})
상세 정보 : http://vitomd.com/blog/coding/tag-communication-in-riot-js-part-2/