use <script setup> syntax

This commit is contained in:
Nebel 2022-08-01 21:07:11 +09:00
parent 24af861ca5
commit 694144907f
2 changed files with 31 additions and 34 deletions

View file

@ -16,7 +16,7 @@
```js
// src/App.vue
{{#include ../frontend/src/App.vue:14:15}}
{{#include ../frontend/src/App.vue:14:16}}
```
このエンドポイントURLを自分の作成したプロジェクトのものに書き換えると完成です。

View file

@ -1,4 +1,4 @@
<script>
<script setup>
import { ref, onMounted } from "vue";
import { QuillEditor } from "@vueup/vue-quill";
import "@vueup/vue-quill/dist/vue-quill.snow.css";
@ -11,17 +11,13 @@ const id =
window.localStorage.setItem("id", id);
// REST API`memo-demo` Hasura Cloud
// REST API
// `memo-demo` Hasura Cloud
const endpoint = `https://memo-demo.hasura.app/api/rest/page/${id}`;
export default {
components: { QuillEditor },
setup() {
const editor = ref();
onMounted(async () => {
console.log("endpoint", endpoint);
const res = await axios.get(endpoint);
const content = res.data.page?.content ?? {
const initialContent = { ops: [{ insert: "読み込み中…" }] };
const defaultContent = {
ops: [
{ insert: "メモ帳\n", attributes: { header: 1 } },
{ insert: "こんにちは!\n" },
@ -29,28 +25,29 @@ export default {
{
insert:
"ここに入力した内容は自動的にHasuraに送信されデータベースに保存されます。\n",
attributes: {
link: endpoint,
},
attributes: { link: endpoint },
},
],
};
console.log("content", content);
onMounted(async () => {
console.log("endpoint", endpoint);
const res = await axios.get(endpoint);
const content = res.data.page?.content ?? defaultContent;
editor.value.setContents(content);
console.log("content", content);
});
const update = debounce(async (content) => {
await axios.put(endpoint, { content });
console.log("updated", content);
}, 1000);
return { editor, update };
},
};
</script>
<template>
<QuillEditor
ref="editor"
:content="{ ops: [{ insert: '読み込み中…' }] }"
:content="initialContent"
@update:content="update"
toolbar="full"
/>