mercredi 4 mai 2016

handle multiple returned data in $http.get() in vuejs

My controller needs to return two variables to the $http.get() function: how do i access both the returned data in the function?. I am mentioning my code below (the code below handles only one data returned): My vue instance:

var vm = new Vue({
    el: '#userMgt',
    data: {

    },
    methods: {
        fetchUser: function () {
            this.$http.get('../api/users', function (data) {
                this.$set('users', data)
            });
        }
    },
    ready: function () {
        this.fetchUser()
    }


});

Then my controller returning the value:

public function index()
    {
        $userRecords = AdminUser::LeftJoin('pltblusertype', 'tbluser.usUserTypeID', '=', 'pltblusertype.utID')
            ->select('tbluser.id', 'tbluser.usName', 'tbluser.email', 'pltblusertype.utName')
            ->get();

        $roles = Role::all();

        return compact('userRecords','roles');

    }

can i do it like this?

var vm = new Vue({
    el: '#userMgt',
    data: {

    },
    methods: {
        fetchUser: function () {
            this.$http.get('../api/users', function (data1,data2) {
                this.$set('users', data1)
                this.$set('roles', data2)
            });
        }
    },
    ready: function () {
        this.fetchUser()
    }


});



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/24xVadE
via IFTTT

Aucun commentaire:

Enregistrer un commentaire