Attempt at making miragejs work

This commit is contained in:
Jef Roosens 2021-12-19 20:57:28 +01:00
parent f9acc17263
commit 1d14f39642
Signed by: Jef Roosens
GPG key ID: 955C0660072F691F
6 changed files with 237 additions and 55 deletions

View file

@ -0,0 +1,42 @@
<template>
<ul>
<li v-for="section in sections">
{{ section.title }}
</li>
</ul>
</template>
<script setup>
import { makeServer } from "../mirage/index.js"
const environment = 'development'
makeServer({ environment })
/* let sections = [ */
/* {"title": "Loading..."} */
/* ] */
/* fetch("/api/v1/test").then( */
/* (res) => { */
/* if (res.ok()) { */
/* return res.json() */
/* }else{ */
/* sections = [{"title": "Error"}] */
/* } */
/* } */
/* ).then( */
/* res => sections = res */
/* ) */
</script>
<script>
export default {
data() {
return {
sections: [{"title": "Loading..."}]
}
},
mounted() {
fetch("/api/v1/test").then(res => res.json()).then(res => sections = res)
}
}
</script>

12
src/mirage/index.js Normal file
View file

@ -0,0 +1,12 @@
import { createServer } from 'miragejs';
export function makeServer({ environment = 'test' }) {
return createServer({
environment,
routes() {
this.namespace = "api/v1";
this.get("/test", () => "yeet");
}
})
}

View file

@ -1,9 +1,13 @@
---
import MenuBar from "../components/MenuBar.vue";
---
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
</head>
<body>
<MenuBar client:load />
<h1>Hi!</h1>
</body>
</html>