0

I am trying to get a list of products from an api with a mixture of vue components and the vue-router setup. I am able to console.log data out inside the function that gets the data but I am unable to get this data rendered out in the view so I can see real data on the root that the component is registered to. My gist is below for you:

https://gist.github.com/mdunbavan/65c9ad008ef06bc1c9058d76507e864e

The main areas where it looks to be getting the data is:

template: '#people-listing-template',
    data: function() {
        return {
            products: []
        }
    },
    mounted: function() {
        this.getAllProducts();
    },

    methods: {
        getAllProducts: function(){

            this.$http.get('/collections/homepage/products.json').then(function (response) {

                $.each(response.data, function(key, value) {
                    this.products.push(value.id);
                }.bind(this));


            }.bind(this), function (response) {

                console.log('error getting products');

            });

        }
    },

Please can someone tell me if there is anything wrong with this code and why it would not render the data inside the root template view?

M dunbavan
  • 1,157
  • 5
  • 22
  • 57
  • So you want to have data from `people-listing` into Vue root instance ? – Belmin Bedak Feb 07 '17 at 20:40
  • Yes did you see the gist its in there with it all – M dunbavan Feb 07 '17 at 20:48
  • Well then you will need some kind of store for this.VueJS Provide their official solution called Vuex inspired by Redux and Flux.However if It's way too much for you, you can check my answer here http://stackoverflow.com/questions/40410332/vuejs-access-child-components-data-from-parent/40411389#40411389. – Belmin Bedak Feb 07 '17 at 20:50
  • 2
    The code you're showing us should definitely be working - I literally copy-pasted it into a JSFiddle, replaced the url with a working one, wrote a basic template and [it works](https://jsfiddle.net/yMv7y/2248/). – mzgajner Feb 07 '17 at 23:23

0 Answers0