improve v-model example

This commit is contained in:
Philipp Kühn 2020-11-13 15:30:09 +01:00
parent 2cf8137def
commit 5bccbacf32
4 changed files with 50 additions and 22 deletions

View File

@ -82,7 +82,7 @@ export default {
computed: {
mainFile() {
const file = this.files
.find(item => item.path.endsWith('.vue') || item.path.endsWith('.jsx'))
.find(item => item.path.endsWith('index.vue') || item.path.endsWith('.jsx'))
if (!file) {
return
@ -122,7 +122,7 @@ export default {
.filter(item => {
return ['vue', 'jsx', 'scss'].includes(item.extension)
})
.sortBy(item => item.path.split('/').length)
.sortBy(item => item.path.split('/').length && !item.path.endsWith('index.vue'))
.toArray()
},
}

View File

@ -1,12 +1,11 @@
<template>
<div>
<editor-content :editor="editor" />
</div>
<editor-content :editor="editor" />
</template>
<script>
import { Editor } from '@tiptap/core'
import EditorContent from './EditorContent.ts'
import { EditorContent } from '@tiptap/vue'
import { defaultExtensions } from '@tiptap/starter-kit'
export default {
components: {
@ -15,15 +14,9 @@ export default {
props: {
value: {
type: [String, Object],
type: String,
default: '',
},
extensions: {
type: Array,
required: true,
default: () => [],
},
},
data() {
@ -32,9 +25,21 @@ export default {
}
},
watch: {
value(value) {
const isSame = this.editor.getHTML() === value
if (isSame) {
return
}
this.editor.commands.setContent(this.value, false)
},
},
mounted() {
this.editor = new Editor({
extensions: this.extensions,
extensions: defaultExtensions(),
content: this.value,
})

View File

@ -1,26 +1,50 @@
<template>
<div>
<full-editor v-model="content" :extensions="extensions" />
<div>
{{ content }}
<editor v-model="content" />
<div class="content">
<h3>Content</h3>
<pre><code>{{ content }}</code></pre>
</div>
</div>
</template>
<script>
import { FullEditor } from '@tiptap/vue'
import { defaultExtensions } from '@tiptap/starter-kit'
import Editor from './Editor'
export default {
components: {
FullEditor,
Editor,
},
data() {
return {
extensions: defaultExtensions(),
content: '<p>A Vue.js wrapper component for tiptap to use <code>v-model</code>.</p>',
}
},
}
</script>
<style lang="scss">
.content {
padding: 1rem 0 0;
h3 {
margin: 1rem 0 0.5rem;
}
pre {
border-radius: 5px;
color: #333;
}
code {
display: block;
white-space: pre-wrap;
font-size: 0.8rem;
padding: 0.75rem 1rem;
background-color:#e9ecef;
color: #495057;
}
}
</style>

View File

@ -1,4 +1,3 @@
export * from '@tiptap/core'
export { default as VueRenderer } from './VueRenderer'
export { default as EditorContent } from './components/EditorContent'
export { default as FullEditor } from './components/FullEditor.vue'