如果没有安装 先npm
npm install vue-quill-editor --save
引入
import { quillEditor } from "vue-quill-editor";
import "quill/dist/quill.core.css";
import "quill/dist/quill.snow.css";
import "quill/dist/quill.bubble.css";
初始化编辑器
<template>
<quill-editor ref="myTextEditor" v-model="content" :options="quillOption">
</quill-editor>
</template>
配置
export default {
components: {
quillEditor,
},
mounted() {
this.quillOption.initButton();
},
data() {
return {
content: "<h2>freddy</h2>",
quillOption: {
theme: "snow",
placeholder: "",
modules: {
toolbar: {
container: [
["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", "link", "image", "video"],
["addBtn"],
],
handlers: {
addBtn: () => {
this.btnMethod();
},
},
},
},
initButton: function () {
const addBtn= document.querySelector(".ql-addBtn");
addBtn.style.cssText =
"width:40px; border:1px solid #ccc; border-radius:5px;font-size:20px;padding-bottom:30px;";
addBtn.className = "iconfont icon-reset";
},
},
};
},
methods: {
btnMethod() {
console.log(this);
},
},
};