0

Add GET endpoints using the axios mock adapter.

How to I return in my Vue component:

my mock api file:

var axios = require("axios");
var MockAdapter = require("axios-mock-adapter");

// This sets the mock adapter on the default instance
var mock = new MockAdapter(axios);

mock.onGet("/users").reply(200, {
  users: [{ id: 1, name: "John Smith" }],
});

In my Vue3 component I have:

<script lang="ts">
import { axios } from "@/api/api";
import { ref, onMounted } from "vue";
export default {
   setup() {
      const heading = ref("Page title");
      const user = [];

      async onMounted(() => {
         const response = await axios.get("/users").then(function (response) {
            this.user = response.data;
         });
      });

      return { heading, user };
   },
};
</script>

But this isnt working, is there something obvious I am doing wrong here?

Pianoc
  • 763
  • 1
  • 11
  • 32

0 Answers0