Answer the question
In order to leave comments, you need to log in
How to use axios in Vue 3 with Typescript?
I need to make a request to the server with axios, get all posts and output all posts
How can I use axios in a Vue 3 project with Typescript?
well, or at least without typescript
Please provide an example with a get and post request
What I tried:
Created a file for the axios service in the directory service
SnippetsService.ts
import axios from "axios";
export default class SnippetsService {
public static getAllSnippets() {
return axios.get("http://localhost:13050/snippets");
}
}
setup() {
let allSnippets = ref({});
created(() => {
allSnippets = SnippetsService.getAllSnippets()
.then(response => {
console.log(response);
allSnippets = response;
})
.catch(error => {
console.log(error);
});
});
return { allSnippets };
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question