Attempt at making miragejs work
This commit is contained in:
parent
f9acc17263
commit
1d14f39642
6 changed files with 237 additions and 55 deletions
42
src/components/MenuBar.vue
Normal file
42
src/components/MenuBar.vue
Normal 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
12
src/mirage/index.js
Normal 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");
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -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>
|
||||
|
|
|
|||
Reference in a new issue