vue-quill-editor富文本编辑器详解

1、通过npm安装vue-quill-editor

在cmd输入命令:npm install vue-quill-editor --save

2、在main.js中引入vue-quill-editor

import VueQuillEditor from 'vue-quill-editor'//引入vue-quill-editor富文本编辑器
Vue.use(VueQuillEditor)//vue使用vue-quill-editor富文本编辑器

//这三个css可以在main.js中引入,也可以在具体使用的.vue文件中引入,一定要引入,不然样式会乱
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'

3、vue页面中使用vue-quill-editor

最下面的样式可以根据自己需求去调,高度要加优先级,不然不会生效。

<template>
    <el-row>
		<quill-editor :options="editorOption" @blur="onEditorBlur($event)" @focus="onEditorFocus($event)" @change="onEditorChange($event)">
		</quill-editor>
	</el-row>
</template>

<script>
	export default {
		data: function() {
			return {
				
				editorOption: {}
			}
		},
		methods: {
			onEditorBlur(editor) { //失去焦点事件 
			},
			onEditorFocus(editor) { //获得焦点事件
			},
			onEditorChange({
				editor,
				html,
				text
			}){ //编辑器文本发生变化
				console.log();
			}
			
		}
	}
</script>

<style>
	.ql-toolbar.ql-snow {
		text-align: left;
	}

	.ql-editor {
		height: 300px !important;
	}
</style>

 

4、最后看一下页面效果,另外头部的功能都是可以选择性展示的

`vue-quill-editor` 是一个基于 `Quill.js` 的富文本编辑器组件,它提供了丰富的配置选项,可以根据需求进行定制。其中 `editorOption` 就是一个非常重要的配置项,它用来配置 `Quill.js` 的选项。 下面是 `editorOption` 的一些常见配置选项及其含义: - `modules`:配置 `Quill.js` 的模块。可以配置的模块包括 toolbar、syntax、history 等。例如,可以通过设置 `modules.toolbar` 来配置工具栏的选项。 - `placeholder`:设置编辑器的占位符文本。 - `readOnly`:设置编辑器是否只读。 - `theme`:设置编辑器的主题。可以设置为 `"snow"`(默认)或 `"bubble"`。 - `bounds`:设置编辑器的边界。可以设置为 `"self"`(默认,表示编辑器本身)或 `"window"`。 - `formats`:配置支持的格式。可以配置的格式包括 bold、italic、underline、strike、link 等。 - `style`:自定义编辑器的样式。 - `scrollingContainer`:设置编辑器的滚动容器。 - `toolbar`:配置工具栏的选项。包括工具栏的位置、按钮的配置等。 除了上述常见配置选项外,还有许多其他的配置选项,可以根据需求进行定制。需要注意的是,`editorOption` 是一个对象,可以通过直接修改对象的属性来进行配置,也可以通过传递一个包含配置选项的对象来进行配置。例如: ```javascript <template> <div> <vue-quill-editor :editor-option="editorOption"></vue-quill-editor> </div> </template> <script> export default { data () { return { editorOption: { 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'], ['link', 'image', 'video'] ] }, placeholder: '请输入内容...', theme: 'snow' } } } } </script> ``` 以上示例中,通过 `editorOption` 对象来配置了工具栏、占位符文本和主题。其中,工具栏的配置项比较复杂,包括了许多按钮的配置,可以根据需求进行定制。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

邹田聪

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值