1.0.3 • Published 3 years ago

vue-wangeditor-ts v1.0.3

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

vue-wangeditor-ts 是基于 wangEditor 二次封装的适配于 vue3.0 + ts 的组件

基本使用

npm i vue-wangeditor-ts --save

模板页面

<template>
	<div class="container">
		<wang-editor v-model="value" ref="editor"></wang-editor>
	</div>
</template>

<script lang="ts">
import { defineComponent, ref, Ref } from 'vue'
import WangEditor from 'vue-wangeditor-ts'
export default defineComponent({
	components: {
		WangEditor,
	},
	setup() {
		const value = ref('')

		return {
			value,
		}
	},
})

// 父组件
const editor<typeof WangEditor.prototype | null> = ref(null)

// 清空富文本
editor.value.clear()
</script>

props api

参数说明类型默认值
value(v-model)富文本默认值string
disabled是否禁用编辑器booleanfalse
height富文本高度number400
zIndex富文本 z-indexnumber500
placeholder富文本 placeholerstring请输入内容
focus是否自动获取焦点booleanfalse
showFullScreen是否显示全屏按钮booleantrue
menus自定义菜单MenuType参考下方 MenuType 类型
fontNames自定义字体string[]
changeTimeout监听富文本 change 事件的频率number200(ms)
pasteFilterStyle关闭粘贴样式的过滤booleanfalse
pasteIgnoreImg忽略粘贴内容中的图片booleanfalse
uploadImgMaxSize限制图片大小number10(M)
accept限制图片上传类型string[]['jpg', 'jpeg', 'png', 'gif', 'bmp']
uploadImgMaxLength最多一次上传几张图片number100
showLinkImg隐藏插入网络图片booleantrue
isEditor编辑时,内容是 ajax 获取。传入富文本请开启此属性booleanfalse

数据类型

MenuType

type MenusType =
	| 'head'
	| 'bold'
	| 'fontSize'
	| 'fontName'
	| 'italic'
	| 'underline'
	| 'strikeThrough'
	| 'indent'
	| 'lineHeight'
	| 'foreColor'
	| 'backColor'
	| 'link'
	| 'list'
	| 'todo'
	| 'justify'
	| 'quote'
	| 'emoticon'
	| 'image'
	| 'video'
	| 'table'
	| 'code'
	| 'splitLine'
	| 'undo'
	| 'redo'

Events 事件

事件名称说明类型回调参数
onFocus获取焦点触发(html: string) => void返回当前富文本片段
onBlur失去焦点触发(html: string) => void返回当前富文本片段
linkImgCallback插入网络图片回调事件({src, alt, href}: { src: stirng, alt: string, href: string }) => viod返回当前图片 src, 图片说明, 跳转连接
lineVideoCallback自定义检查插入视频的回调(video: string) => void返回当前视频
html获取 html 内容(html: () => void) => void返回获取 html 内容的函数
text获取 text 文本(text: () => void) => void返回获取 text 内容的函数
customUploadImg自定义图片上传({resultFiles, insertImgFn}: {resultFiles: File[], insertImgFn: (url: string) => void}) => voidresultFiles 是 input 中选中的文件列表,insertImgFn 是获取图片 url 后,插入到编辑器的方法
customUploadVideo自定义上传视频({resultFiles, insertVideoFn}: {resultFiles: File[], insertVideoFn: (url: string) => void}) => voidresultFiles 是 input 中选中的文件列表,insertImgFn 是获取图片 url 后,插入到编辑器的方法
customInsertVideo自定义视频播放器(videoUrl: string) => void返回视频地址

插件不满足要需求时,请到官网扩展插件