slate-react library implemented with vue3
- ✨ Highly customizable features, use slate core at the bottom level
- ⚡ Use vue3 for high-performance rendering, and later connect to vapor mode
- ☕ The latest version of the core, design tends to be stable
- 👉 Check out the live demo of all of the examples
npm install slate-vue3
2. Now, you can use it in vue-sfc 👉 live demo
<script setup lang="ts">
import { h } from "vue";
import {
Slate,
Editable,
defaultRenderLeaf,
defaultRenderPlaceHolder,
} from "slate-vue3";
import { createEditor } from "slate-vue3/core";
import { withDOM } from "slate-vue3/dom";
import { withHistory } from "slate-vue3/history";
const initialValue = [
{
type: "paragraph",
children: [{ text: "Let's start" }],
},
];
const renderElement = ({ attributes, children }) =>
h("p", attributes, children);
const editor = withHistory(withDOM(createEditor()));
editor.children = initialValue;
</script>
<template>
<Slate
:editor="editor"
:render-element="renderElement"
:render-leaf="defaultRenderLeaf"
:render-placeholder="defaultRenderPlaceHolder"
>
<Editable />
</Slate>
</template>
This ensures that your rich text is as expected, and slate-vue3 provides some default rendering functions, you can directly use the default rendering behavior
Of coures yes, but we do not recommend it unless you have already configured jsx in the project, as a branch, using the h function directly is already simple enough
Vue uses lazy updates, rendering with components generates additional state, which can cause unexpected results during updates, it would be better to use functions as branches directly