[Vuejs]-How to call service from component which are in different files?

0👍

After you export the getCorporateRequests() and import it in the component

Your getCorporateRequests function is not returning a promise so you cannot use getCorporateRequests().then()

so make your getCorporateRequests() return a promise

filename: service.js
let getCorporateRequests = function() {
   let url = "http://corptest.mocklab.io/thing/2";
   return Vue.axios.get(url);
} 

now in your component you can chain a then() as follows:

service.getCorporateRequests().then(function(data){
    console.log(data);
})`

Leave a comment