You can still create normal ES5-6 classes. You can use that.
May 2, 2016
5
Level 3
Vue add a "service" to the app or component
I want to create a dedicated js service for handling http requests, instead of dirtying my components with:
this.$http.get
stuff, I would us this with a dedicated service, and the components will use it instead, any ideas how do I implement that?
in angular it was called "services" for example...
Level 7
I've done this, from an old project:
UserService.js
import Vue from 'vue'
export default {
getUsers(succes, error) {
Vue.http.get('user').then(
(response) => {
succes(response.data)
},
(response) => {
error(response)
}
)
},
...
}
my views/components:
import UserService from '../../services/UserService'
export default {
ready() {
getUsers() {
UserService.getUsers((data) => {
this.users = data
}, (response) => {
toastr.error("Oops, " + response.status + " " + response.statusText, "Users", toastrOptions);
})
},
...
}
}
Hope this is something for you..
2 likes
Please or to participate in this conversation.