vue frontend
parent
0f5eddeb59
commit
10e7400b5b
@ -0,0 +1,58 @@
|
||||
export default {
|
||||
setup() {
|
||||
const { ref, computed } = Vue;
|
||||
|
||||
const title = ref("");
|
||||
const link = ref("");
|
||||
const overview = ref("");
|
||||
const categories = ref([""]);
|
||||
const date = ref(null);
|
||||
|
||||
const sent = ref(false);
|
||||
const disabled = computed(() => {
|
||||
return [title, overview, overview, categories].some((input) => input.value == "");
|
||||
});
|
||||
|
||||
const submit = function () {
|
||||
fetch("https://hub.xpub.nl/soupboat/padliography/", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
title: title.value,
|
||||
link: link.value,
|
||||
overview: overview.value,
|
||||
categories: categories.value,
|
||||
date: date.value,
|
||||
}),
|
||||
});
|
||||
sent.value = true;
|
||||
|
||||
title.value = "";
|
||||
link.value = "";
|
||||
overview.value = "";
|
||||
categories.value = [""];
|
||||
date.value = null;
|
||||
};
|
||||
|
||||
return { title, link, overview, categories, date, submit, sent, disabled };
|
||||
},
|
||||
|
||||
template: `
|
||||
|
||||
<div class='app-form'>
|
||||
<h2>Add a new pad</h2>
|
||||
<input type="text" v-model="link" placeholder="URL" />
|
||||
<input type="text" v-model="title" placeholder="Title" />
|
||||
|
||||
<input type="text" v-model="overview" placeholder="Description" />
|
||||
<input type="text" v-model="categories[index]" placeholder="Category" v-for="(category, index) in categories" :key="index"/>
|
||||
<button class="add" @click="categories.push('')">+</button>
|
||||
<label for="date">date</label>
|
||||
<input type="date" v-model="date" />
|
||||
|
||||
<button @click="submit">Insert</button>
|
||||
</div>
|
||||
|
||||
|
||||
`,
|
||||
};
|
@ -0,0 +1,33 @@
|
||||
export default {
|
||||
setup() {
|
||||
const { ref, computed } = Vue;
|
||||
|
||||
const pads = ref([]);
|
||||
|
||||
const columns = ["title", "overview", "categories", "date"];
|
||||
|
||||
fetch("http://localhost:3146/")
|
||||
.then((res) => res.json())
|
||||
.then((data) => (pads.value = data));
|
||||
|
||||
return { pads, columns };
|
||||
},
|
||||
template: `
|
||||
<table>
|
||||
<tr class="header">
|
||||
<th v-for="column in columns">{{column }}</th>
|
||||
</tr>
|
||||
<tr v-for="(pad, index) in pads" key="pad.title, index" :class="pad.category">
|
||||
|
||||
|
||||
<td class="title">
|
||||
<a :href="pad.link" target="_blank"> {{pad.title}} </a>
|
||||
</td>
|
||||
<td class="overview">{{pad.overview}}</td>
|
||||
<td class="categories">{{pad.category}}</td>
|
||||
<td class="date">{{pad.date}}</td>
|
||||
|
||||
</tr>
|
||||
</table>
|
||||
`,
|
||||
};
|
@ -0,0 +1,27 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<script src="https://unpkg.com/vue@3"></script>
|
||||
<title>Padliography Bis</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app">
|
||||
<pad-form></pad-form>
|
||||
<pad-table></pad-table>
|
||||
</div>
|
||||
|
||||
<script type="module">
|
||||
import PadForm from "./components/PadForm.js";
|
||||
import PadTable from "./components/PadTable.js";
|
||||
|
||||
const { createApp } = Vue;
|
||||
|
||||
createApp({
|
||||
components: { PadForm, PadTable },
|
||||
}).mount("#app");
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue