1

I misunderstood the documentation of passing child component to other child component.

I have two components

index.html

<main-categories-products source="{{ url('api/products') }}">
</main-categories-products>

<sidebar-options> </sidebar-options>

My app.js

 var app = new Vue({
  el: '#app',
  components: {
    MainCategoriesProducts,
    SidebarOptions
  }

})

MainCategoriesProducts.vue

import Vue from 'vue'
var bus = new Vue()
    export default{
        props: ['source'],
        created(){

            this.fetchedProduct()
        },
        methods: {

            fetchedProduct: function(){


                        var data = [1,2, 3];

                        bus.$emit('did-something', data);


            }
        }
    }

My SidebarOptions.vue

import Vue from 'vue'
    var bus = new Vue()

    export default{

        data(){

            return {

                someData: {}
            }
        },

        created(){

            bus.$on('did-something', data => this.someData = data);
            console.log(this.someData)

        }
    }

No errors but I can't get the data from MainCategoriesProducts to SidebarOptions. How can I get those data = [1, 2, 3]? TY

1 Answer 1

1

You're creating two different buses, and you should just create one.

In app.js add this

window.bus = new Vue();

And remove

var bus = new Vue()

from each of your components.

Sign up to request clarification or add additional context in comments.

1 Comment

@Rbex glad to help :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.