Vue.jsで小規模なSPAを開発している。Vuexを導入するほどでもなく、Vue.jsの標準機能でコンポーネント間でデータをやりとりする方法がないか考えていた。 親子コンポーネント間についてはProps down/Events upでデータのやりとりができる。 子子コンポーネント間(いわゆる兄弟間)はどうするのが良いのかを3つのパターンを紹介する。 $on/$emitでのイベントによるやり取り 親コンポーネントをコントローラにして子コンポーネント間を取り持つ Storeパターンの適用 親子コンポーネント間のデータのやり取りについては、以下の記事を参照してほしい。 $on/$emitでのイベントによるやり取り 一番簡単なのが、この$on/$emitでのイベントによるやり取り。 共有のViewModel(vueインスタンス)を用意し、そこにイベントを登録/発火させることで親子に関係なくデータ