I just started with VUE and I am stuck.
I have a simple VUE component and the script part of it is:
<script>
import Dish from './dish.vue'
import SearchBar from './search.vue'
import axios from 'axios'
export default {
components: {Dish, SearchBar},
name: "selectDish",
data() {
return {
dishes : []
}
},
mounted(){
axios.get('http://example.com/',{method :'GET'})
.then(response =>{
console.log(response);
this.dishes=response.data
})
}
}
What I am trying to achieve is to remove the axios API GET call that I have inside the VUE compoennt as above and instead call the function that I have written inside my APIService.TS file which ultimately makes the GET call.
My apiService.ts file is as Below:
import Promise, { config, resolve, reject } from 'bluebird';
import Config from '../config';
import axios from 'axios';
export class APIService{
constructor(){ }
public giveMeAllDishes(dishType, query) : Promise<string>{
return new Promise((resolve,reject) =>{
axios.get('http://example.com',{method : 'GET'})
.then(function(respone){
console.log(respone);
resolve(respone.data);
})
.catch(function(err){
reject(err);
})
})
}
}
When I put the import APIService from '../../services/apiService' inside the VUE component, I get an error saying :
ERROR in ./~/babel-loader/lib!./~/vue-loader/lib/selector.js?type=script&index=0!./src/components/selectDish/selectDish.vue
Module not found: Error: Can't resolve '../../services/apiService'
Also, when I solve this referencing issue, How can I call the 'giveMeAllDishes' function of API Service from VUE Component ?
axios.get()call in a newPromise. This is the classic promise construction anti-pattern