Class import into Vue component

488
May 12, 2017, at 8:08 PM

I want to make separate class for axios requests, which works like "service"

Vue component:

<template>
    <div v-for="user in users">
        {{ user.firstname }} - {{ user.lastname }} - {{ user.middlename }}
    </div>
</template>
<script>
    import ConnectionService from './ConnectionService';
    const connectionService = new ConnectionService();
    export default {
        mounted() {
            console.log('Component is mounted');
        },
        created() {
            this.users = connectionService.getSingleInstance('http://laravelapi/user');
            console.log("This are users " + this.users);
        },
        data() {
            return {
                users: [],
            }
        }
    }
</script>

And the service is the following:

export default class ConnectionService {
    getSingleInstance(path) {
        console.log('This is path ' + path);
        let axios_data = {};
        axios.get(path).then(response => axios_data = response.data.result);
        console.log('This is data ' + axios_data);
        console.log(axios_data);
        return axios_data;
    }

}

As I can see in my console, I get the data from axios xhr request, but then they are not passed to the Vue Component, because I get empty object in the string console.log("This are users " + this.users);

How to import COnnectionService properly and then use it in Vue Component?

Rent Charter Buses Company
READ ALSO
Prototype mobile app development

Prototype mobile app development

I have experience in C/C++, Java and JavaScript and over the next 52 hours I need to develop an app that allows bookings at a certain location and for people to accept the booking, similar to Air BnB

323
Imitations key comitation in JavaScript

Imitations key comitation in JavaScript

There is a need to simulate different key combinationsSuch as ctrl+a ctrl+s ctrl+alt+delete and bind them on the div in the interface

409
Google Adwords Shopping Content - how to get product title and image of a product?

Google Adwords Shopping Content - how to get product title and image of a product?

Is there any possible way of getting product attributes such as product title, image link, etc other than using Google Shopping Content?

382
res.location is not setting page url

res.location is not setting page url

I just need a hard coded password protected pageI used href to redirect to a page as /admin/user/password:

382