Vue + FexAPI
Use FexAPI as your mock backend during Vue development.
Setup
bash
npx fexapi@latest initbash
pnpm dlx fexapi@latest initbash
bunx fexapi@latest initbash
yarn dlx fexapi@latest initEdit fexapi/schema.fexapi:
txt
port: 4000
GET /users:
id:uuid
name:name
email:emailbash
npx fexapi@latest generate
npx fexapi@latest dev --watchbash
pnpm dlx fexapi@latest generate
pnpm dlx fexapi@latest dev --watchbash
bunx fexapi@latest generate
bunx fexapi@latest dev --watchbash
yarn dlx fexapi@latest generate
yarn dlx fexapi@latest dev --watchEnable CORS in fexapi.config.js:
js
module.exports = {
port: 4000,
cors: true,
};Composition API
vue
<script setup>
import { ref, onMounted } from "vue";
const users = ref([]);
const loading = ref(true);
onMounted(async () => {
const res = await fetch("http://localhost:4000/users?count=10");
const data = await res.json();
users.value = data.users;
loading.value = false;
});
</script>
<template>
<p v-if="loading">Loading...</p>
<ul v-else>
<li v-for="user in users" :key="user.id">
{{ user.name }} — {{ user.email }}
</li>
</ul>
</template>Package Scripts
json
{
"scripts": {
"dev": "vite",
"mock": "fexapi dev --watch --log",
"dev:full": "concurrently \"npm run dev\" \"npm run mock\""
}
}