Created
December 20, 2016 00:43
-
-
Save afucher/874d110f97706a075600e8da3eb74b1e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
import Vue from 'vue'; | |
export default { | |
getCourses() { | |
return Vue.resource('/courses').get(); | |
}, | |
putCourses(){ | |
return Vue.resource('/courses').put(); | |
} | |
} |
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?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Isso não seria nem relacionado ao Vue, só JS.. você poderia fazer algo do tipo: