Vue + Element UI使用富文本编辑器

第一步下载组件

npm install vue-quill-editor 

第二步在需要使用的组件内引入· 富文本组件

import { quillEditor } from 'vue-quill-editor'

同时引入相关css

import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'

因为是个组件所以要注册才能使用

components: {
    quillEditor
  }

放到视图容器中


提交

基本配置

data () {
  return {
    content: '',
    editorOption: {} 
  }
},
methods: {
  submit () {
    console.log(this.$refs.text.value)
  }
}
// editorOption里是放图片上传配置参数用的,例如:
// action:  '/api/product/richtext_img_upload.do',  // 必填参数 图片上传地址
// methods: 'post',  // 必填参数 图片上传方式
// token: '',  // 可选参数 如果需要token验证,假设你的token有存放在sessionStorage
// name: 'upload_file',  // 必填参数 文件的参数名
// size: 500,  // 可选参数   图片大小,单位为Kb, 1M = 1024Kb
// accept: 'multipart/form-data, image/png, image/gif, image/jpeg, image/bmp, image/x-icon,image/jpg'  // 可选 可上传的图片格式

一切准备完成以后点击提交按钮就可以看见自己在富文本输入的内容啦~~


Vue + Element UI使用富文本编辑器_第1张图片
富文本大小可以根据父元素调整
Vue + Element UI使用富文本编辑器_第2张图片
控制台打印出来的图片

到这里就分享完咯,小伙伴们有更好用,更方便的富文本可以推荐一下呦~~

你可能感兴趣的:(Vue + Element UI使用富文本编辑器)