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

View file

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