https://www.cnblogs.com/toughy/p/11283234.html
安裝:
npm install vue-quill-editor --save
安裝Vue-Quill-Editor需要依賴:
npm install quill --save
在入口文件main.js 中引入
import QuillEditor from 'vue-quill-editor' import 'quill/dist/quill.core.css' import 'quill/dist/quill.bubble.css' import 'quill/dist/quill.snow.css' Vue.use(QuillEditor)
在需要的組件中使用 代碼如下:
<template>
<div class="content edit_container">
<quill-editor
v-model="content"
ref="myQuillEditor"
:options="editorOption"
@blur="onEditorBlur($event)" @focus="onEditorFocus($event)"
@change="onEditorChange($event)">
</quill-editor>
<button v-on:click="saveHtml">保存</button>
</div>
</template>
<script>
export default {
data () {
return {
content: `<p>hello world</p>`,
editorOption: {
theme: 'snow'
},
modules: {
toolbar: [
// ['bold', 'italic', 'underline', 'strike'],
// ['blockquote', 'code-block'],
// [{ 'header': 1 }, { 'header': 2 }],
// [{ 'list': 'ordered'}, { 'list': 'bullet' }],
// [{ 'script': 'sub'}, { 'script': 'super' }],
// [{ 'indent': '-1'}, { 'indent': '+1' }],
// [{ 'direction': 'rtl' }],
// [{ 'size': ['small', false, 'large', 'huge'] }],
// [{ 'header': [1, 2, 3, 4, 5, 6, false] }],
// [{ 'color': [] }, { 'background': [] }],
// [{ 'font': [] }],
// [{ 'align': [] }],
// ['clean'],
// ['image','video']
]
}
}
},
computed: {
editor () {
return this.$refs.myQuillEditor.quill
}
},
methods: {
onEditorReady (editor) { // 准備編輯器
},
onEditorBlur () {}, // 失去焦點事件
onEditorFocus () {}, // 獲得焦點事件
onEditorChange () {}, // 內容改變事件
saveHtml (event) {
alert(this.content)
}
}
}
</script>
<style>
#app {
font-family: 'Avenir', Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>
這樣就完成一個簡單的富文本編輯器

