Vue.js: define a service

Vue.js: define a service

Asked on November 17, 2018 in vue.js.
Add Comment

  • 1 Answer(s)

    As per Vue.js,
    Vue.js is not a complete framework. It has attention on view layer. Library focus on V from MVC. So, it doesn’t offer services.
    If you are using module loader alike Browserify or webpack. Now, you can control the module structure of ES6 and produce service. Then generate a simple javascript class that will be spread by a new module.

    For instance:

    export default class RestResource {
     sendRequest() {
       // Use vue-resource or any other http library to send your request

    Use service inside vue element 1 & 2 by import class.

    import RestResource from './services/RestResource';
    const restResourceService = new RestResource();


    Answered on November 17, 2018.
    Add Comment

  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.