FastMock:模拟后端接口

174 阅读1分钟

当后端大哥接口暂时没有写好时,就可以暂时使用 FastMock 来模拟,以提前查看效果。

  • FastMock 添加成功后的界面

image.png

  • 可以在 FastMock 中模拟后端要发送的数据格式

image.png

  • 在 Vue 中使用 axios 发送 get 请求
<template>
  <button id="app" @click="sendGet">点击发送 get 请求</button>
</template>

<script>
const axios = require("axios")
export default {
  methods: {
    sendGet() {
      axios.get("https://www.fastmock.site/mock/e68d869253f9e376375eb399ba932142/test/api1").then((res) => {
        console.log(res.data)
      })
    }
  }
}
</script>
  • 成功返回的 JSON 数据

image.png