1

i'm trying to use one axios.get instead of typing it mutiple times

this is my script tag


<script>
import axios from "axios";
export default {
  data() {
    return {
 blogs:"",
      categories: "",
      owners: ""
    };
  },
  async mounted() {
    axios.get("http://localhost:4000/api/blogs").then(res => {
      console.log(res);
      this.blogs = res.data.blogs;
    });
    axios.get("http://localhost:4000/api/categories").then(res => {
      console.log(res);
      this.categories = res.data.categories;
    });
    axios.get("http://localhost:4000/api/owners").then(res => {
      console.log(res);
      this.owners = res.data.owners;
    });
  },
 
};
</script>

please how can i go about this

jibzy
  • 539
  • 2
  • 11
  • `mounted` doesn't need to be async since none of the axios calls are awaited. – evolutionxbox Oct 06 '22 at 13:59
  • You cannot query multiple URLs with one GET request. What are you trying to do? Having those three requests is not an issue as long as the response is cached properly. – Peter Krebs Oct 06 '22 at 14:03
  • @PeterKrebs I'm trying to use axios.all to call all requests – jibzy Oct 06 '22 at 14:24
  • Does this answer your question? [How to post multiple Axios requests at the same time?](https://stackoverflow.com/questions/61385454/how-to-post-multiple-axios-requests-at-the-same-time) – evolutionxbox Oct 06 '22 at 14:26
  • @jibzy map your URLs to `axios.get()` calls (promises) and then use `Promise.all()` to assign the results to `this` properties. Or, use `axios.all()` helper. – Robo Robok Oct 06 '22 at 14:33

0 Answers0