Modified2 years ago. I would like to use axios in vue (Typescript) but I get into trouble with my code.
Thank you for your time and solution. 3030 bronze badges. I'm encapsulate HTTP/REST operations in separate .ts files. Here I also use async/await to have better readable code. Each method declared its input and return types.
Andreas BauerAndreas Bauer. Are you sure to use POST request? It seems like GET request because of 'GetTreeTenant' and you can try only axios instead $axios.
In typescript,we can use module augmentation.https://vuejs.org/v2/guide/typescript.html#%E5%A2%9E%E5%BC%BA%E7%B1%BB%E5%9E%8B%E4%BB%A5%E9%85%8D%E5%90%88%E6%8F%92%E4%BB%B6%E4%BD%BF%E7%94%A8.
- I want to suggest you use a service for your http request using axios. I would do this by separating my http services into separate files.
- Say you have an API and you use a resource say hero then the code will look something like this:. For hero service you could do this:. 33 gold badges3737 silver badges4343 bronze badges.
4343 bronze badges. One quick and dirty solution would be to set your Vue object to type any. TypeScript is letting you know that it doesn't recognize the $axios property on the Vue Object.