Join the Stack Overflow Community
Stack Overflow is a community of 6.6 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

alright I have small issue may be but I can't figure it out.

if I pass only one http request using axios all work good.

but when I use multiple request I get result in console log but can't able to send to view file ( laravel blade view file).

let me show you my code :

brand.blade.php

// main element for Vue js el: '#container'
<div id="container" class="row all_brands">
        <brands></brands>
    </div>


// template for brand component
<template id="brand-template">
   <ul>
     // if I only pass one http request through axios then  my data shows here but for multiple request not showing anything.
     <li v-for="brand in list" v-text="brand.brand_id"></li>

   </ul>
   @{{count}}
</template>

brand.js

Vue.component('brands',{

template: '#brand-template',

data: function(){

    return{

        list: [],
        count: ''
    }

},

created: function(){

    //axios.get('api/brands').then(response => this.list = response.data) ; // here I send only one gttp request and working find..

    axios.all([
    axios.get('api/brands'),
    axios.get('api/brand_count')
    ])
        .then(
        axios.spread(
            function (brand, count) {
             // this is not working and not set these data to my brand.blade.php file template
             this.list = brand.data;
             this.count = count.data;
             // console show me all the data that coming from http request  
            //console.log('list',brand.data);
            //console.log('count',count.data);
            }
    ))

}

});


new Vue({

el: '#container'

})

can any one let me how to show data in my view file ?

share|improve this question
up vote 2 down vote accepted

This is happening because scope of this is not correct in axios.spread, earlier it was working for you, as you were using es6 arrow function, which automatically binds this scope.

You can make following changes to make it work:

created: function(){
    var that = this    
    axios.all([
    axios.get('api/brands'),
    axios.get('api/brand_count')
    ])
        .then(
        axios.spread(
            function (brand, count) {
             that.list = brand.data;
             that.count = count.data;
            }
    ))

}
share|improve this answer
    
Thanks man. very smart answer. – watson Jan 13 at 8:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.