Skip to content

Instantly share code, notes, and snippets.

@afucher
Created December 20, 2016 00:43
Show Gist options
  • Save afucher/874d110f97706a075600e8da3eb74b1e to your computer and use it in GitHub Desktop.
Save afucher/874d110f97706a075600e8da3eb74b1e to your computer and use it in GitHub Desktop.
'use strict';
import Vue from 'vue';
export default {
getCourses() {
return Vue.resource('/courses').get();
},
putCourses(){
return Vue.resource('/courses').put();
}
}
@fdaciuk
Copy link

fdaciuk commented Dec 20, 2016

Ou pra não usar singleton, pode fazer algo do tipo:

'use strict';

import Vue from 'vue';

export default () => ({
    resource: Vue.resource('/courses'),

    getCourses() {
        return this.resource.get();
    },
    putCourses(){
        return this.resource.put();
    }
})

E no arquivo que você for importar esse CourseService, você faz assim:

import CourseService from './CourseService'

// e execute a função no momento em que o `Vue.resource` deveria estar disponível
const course = CourseService()

// agora você pode usar o get, put, etc
course.getCourses()
course.putCourses()

Sacou?

@afucher
Copy link
Author

afucher commented Dec 20, 2016

Valeu @fdaciuk! Juntei o que você falou com essa issue e deu certo! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment