yarn add @vueup/vue-quill
<QuillEditor
ref="quillDom"
v-model:content="ruleForm.desc"
:options="custOptions"
content-type="html"
:style="{ height: '400px', width: '615px' }"
/>
import { QuillEditor } from '@vueup/vue-quill';
import '@vueup/vue-quill/dist/vue-quill.snow.css';
const quillDom = ref();
const toolbarOptions = [
['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'],
];
const checkImgType = (file: File) => {
if (/\.(jpg|jpeg|png|GIF|JPG|PNG)$/.test(file.name)) {
return true;
}
return false;
};
const overrideHandlers = {
image: function image() {
const self = this as any;
if (props.uploadImgFn) {
let fileInput = self.container.querySelector('input.ql-image[type=file]');
if (fileInput === null) {
fileInput = document.createElement('input');
fileInput.setAttribute('type', 'file');
fileInput.classList.add('ql-image');
fileInput.addEventListener('change', function () {
if (checkImgType(fileInput.files[0])) {
props.uploadImgFn(fileInput.files[0], function (imguri: any) {
if (imguri) {
const length = self.quill.getSelection(true).index;
self.quill.insertEmbed(length, 'image', imguri);
self.quill.setSelection(length + 1);
}
fileInput.value = '';
});
} else {
Message.error('只能上传图片!');
}
});
self.container.appendChild(fileInput);
}
fileInput.click();
}
},
};
const custOptions = {
debug: false,
modules: {
toolbar: {
container: toolbarOptions,
handlers: overrideHandlers,
},
},
placeholder: `${t('offers.form.desc')}...`,
theme: 'snow',
};