mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-06-07 17:43:49 +08:00
docs: update content, fix #1821
This commit is contained in:
parent
1fd42ca291
commit
49a99a0410
@ -96,3 +96,69 @@ You should now see Tiptap in your browser. Time to give yourself a pat on the ba
|
|||||||
You’re probably used to bind your data with `v-model` in forms, that’s also possible with Tiptap. Here is a working example component, that you can integrate in your project:
|
You’re probably used to bind your data with `v-model` in forms, that’s also possible with Tiptap. Here is a working example component, that you can integrate in your project:
|
||||||
|
|
||||||
https://embed.tiptap.dev/preview/GuideGettingStarted/VModel
|
https://embed.tiptap.dev/preview/GuideGettingStarted/VModel
|
||||||
|
|
||||||
|
```html
|
||||||
|
<template>
|
||||||
|
<editor-content :editor="editor" />
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { Editor, EditorContent } from '@tiptap/vue-2'
|
||||||
|
import StarterKit from '@tiptap/starter-kit'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
components: {
|
||||||
|
EditorContent,
|
||||||
|
},
|
||||||
|
|
||||||
|
props: {
|
||||||
|
value: {
|
||||||
|
type: String,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
editor: null,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
watch: {
|
||||||
|
value(value) {
|
||||||
|
// HTML
|
||||||
|
const isSame = this.editor.getHTML() === value
|
||||||
|
|
||||||
|
// JSON
|
||||||
|
// const isSame = JSON.stringify(this.editor.getJSON()) === JSON.stringify(value)
|
||||||
|
|
||||||
|
if (isSame) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.editor.commands.setContent(value, false)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
mounted() {
|
||||||
|
this.editor = new Editor({
|
||||||
|
content: this.value,
|
||||||
|
extensions: [
|
||||||
|
StarterKit,
|
||||||
|
],
|
||||||
|
onUpdate: () => {
|
||||||
|
// HTML
|
||||||
|
this.$emit('input', this.editor.getHTML())
|
||||||
|
|
||||||
|
// JSON
|
||||||
|
// this.$emit('input', this.editor.getJSON())
|
||||||
|
},
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
beforeDestroy() {
|
||||||
|
this.editor.destroy()
|
||||||
|
},
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
```
|
||||||
|
@ -103,4 +103,68 @@ You should now see Tiptap in your browser. Time to give yourself a pat on the ba
|
|||||||
## 5. Use v-model (optional)
|
## 5. Use v-model (optional)
|
||||||
You’re probably used to bind your data with `v-model` in forms, that’s also possible with Tiptap. Here is a working example component, that you can integrate in your project:
|
You’re probably used to bind your data with `v-model` in forms, that’s also possible with Tiptap. Here is a working example component, that you can integrate in your project:
|
||||||
|
|
||||||
https://embed.tiptap.dev/preview/GuideGettingStarted/VModel
|
```html
|
||||||
|
<template>
|
||||||
|
<editor-content :editor="editor" />
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { Editor, EditorContent } from '@tiptap/vue-2'
|
||||||
|
import StarterKit from '@tiptap/starter-kit'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
components: {
|
||||||
|
EditorContent,
|
||||||
|
},
|
||||||
|
|
||||||
|
props: {
|
||||||
|
value: {
|
||||||
|
type: String,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
editor: null,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
watch: {
|
||||||
|
value(value) {
|
||||||
|
// HTML
|
||||||
|
const isSame = this.editor.getHTML() === value
|
||||||
|
|
||||||
|
// JSON
|
||||||
|
// const isSame = JSON.stringify(this.editor.getJSON()) === JSON.stringify(value)
|
||||||
|
|
||||||
|
if (isSame) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.editor.commands.setContent(value, false)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
mounted() {
|
||||||
|
this.editor = new Editor({
|
||||||
|
content: this.value,
|
||||||
|
extensions: [
|
||||||
|
StarterKit,
|
||||||
|
],
|
||||||
|
onUpdate: () => {
|
||||||
|
// HTML
|
||||||
|
this.$emit('input', this.editor.getHTML())
|
||||||
|
|
||||||
|
// JSON
|
||||||
|
// this.$emit('input', this.editor.getJSON())
|
||||||
|
},
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
beforeDestroy() {
|
||||||
|
this.editor.destroy()
|
||||||
|
},
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
```
|
||||||
|
@ -133,60 +133,4 @@ You should now see Tiptap in your browser. Time to give yourself a pat on the ba
|
|||||||
## 5. Use v-model (optional)
|
## 5. Use v-model (optional)
|
||||||
You’re probably used to bind your data with `v-model` in forms, that’s also possible with Tiptap. Here is how that would work with Tiptap:
|
You’re probably used to bind your data with `v-model` in forms, that’s also possible with Tiptap. Here is how that would work with Tiptap:
|
||||||
|
|
||||||
```html
|
https://embed.tiptap.dev/preview/GuideGettingStarted/VModel
|
||||||
<template>
|
|
||||||
<editor-content :editor="editor" />
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
import { Editor, EditorContent } from '@tiptap/vue-3'
|
|
||||||
import StarterKit from '@tiptap/starter-kit'
|
|
||||||
|
|
||||||
export default {
|
|
||||||
components: {
|
|
||||||
EditorContent,
|
|
||||||
},
|
|
||||||
|
|
||||||
props: {
|
|
||||||
modelValue: {
|
|
||||||
type: String,
|
|
||||||
default: '',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
editor: null,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
watch: {
|
|
||||||
modelValue(value) {
|
|
||||||
const isSame = this.editor.getHTML() === value
|
|
||||||
|
|
||||||
if (isSame) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
this.editor.commands.setContent(value, false)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
mounted() {
|
|
||||||
this.editor = new Editor({
|
|
||||||
content: this.modelValue,
|
|
||||||
extensions: [
|
|
||||||
StarterKit,
|
|
||||||
],
|
|
||||||
onUpdate: () => {
|
|
||||||
this.$emit('update:modelValue', this.editor.getHTML())
|
|
||||||
},
|
|
||||||
})
|
|
||||||
},
|
|
||||||
|
|
||||||
beforeUnmount() {
|
|
||||||
this.editor.destroy()
|
|
||||||
},
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
Loading…
Reference in New Issue
Block a user