富文本编辑器(vue)

Tinymce(vue 3)

封装组件  下载引入即用

链接:https://pan.baidu.com/s/1t-wTS_7mdSZr8DlgBfBw4A 
提取码:luck

组件中使用

//引入
import tinyMce from "../../../../components/Tinymce/index.vue";
//注册
components: { tinyMce },
//使用
 <tinyMce :value="ruleForm.content" @getTinyData="getTinyData"></tinyMce>
//ruleForm.content  富文本编辑的内容


methods:{
    富文本编辑内容传递
    getTinyData(v) {
            this.ruleForm.content = v;
       },
}

vue-quill-editor (vue 2)

下载Vue-Quill-Editor 

下载quill(Vue-Quill-Editor需要依赖)

npm install vue-quill-editor --save

npm install quill --save

组件中使用

html

<quill-editor
            style="min-height:520px;background:#fff;"
            v-model="formClause.content"
            ref="myQuillEditor"
            :options="editorOption" @blur="onEditorBlur($event)" @focus="onEditorFocus($event)"
            @change="onEditorChange($event)"
          >
          </quill-editor>

js

//引入组件及样式文件
import { quillEditor } from "vue-quill-editor";
import 'quill/dist/quill.core.css';
import 'quill/dist/quill.snow.css';
import 'quill/dist/quill.bubble.css';

// 工具栏配置

const toolbarOptions = [
  ['bold', 'italic', 'underline', 'strike'],        // toggled buttons
  ['blockquote', 'code-block'],

  [{ 'header': 1 }, { 'header': 2 }],               // custom button values
  [{ 'list': 'ordered' }, { 'list': 'bullet' }],
  [{ 'script': 'sub' }, { 'script': 'super' }],      // superscript/subscript
  [{ 'indent': '-1' }, { 'indent': '+1' }],          // outdent/indent
  [{ 'direction': 'rtl' }],                         // text direction

  [{ 'size': ['small', false, 'large', 'huge'] }],  // custom dropdown
  [{ 'header': [1, 2, 3, 4, 5, 6, false] }],

  [{ 'color': [] }, { 'background': [] }],          // dropdown with defaults from theme
  [{ 'font': [] }],
  [{ 'align': [] }],
  ['link', 'image'],
  ['clean']                                         // remove formatting button
]


export default {
//引入组件
components: {
    quillEditor
  }
  data() {
    return {
        editorOption: {
        placeholder: '请输入文本...',
        theme: 'snow',
        modules: {
          toolbar: {
            container: toolbarOptions,
            handlers: {
              'image': function () {
                document.querySelector('.avatar-uploader input').click()
              }
            }
          }
        }
      },
    }
  }
    methods:{
onEditorReady(editor) { // 准备编辑器
 
        },
        onEditorBlur(){}, // 失去焦点事件
        onEditorFocus(){}, // 获得焦点事件
        onEditorChange(){}, // 内容改变事件
async upload(image) {
      let fromddata = new FormData()
      fromddata.append('image', image)
      fromddata.append('houseid', this.clauseId)
      fromddata.append('token', getToken())
      let clauseData = await Adminclauseapplyimg(fromddata);
      // 获取富文本组件实例
      let quill = this.$refs.myQuillEditor.quill
      // 如果上传成功
      if (clauseData.code === 200) {
        // 插入图片  res.info为服务器返回的图片地址
        quill.insertEmbed(length, 'image', request.interceptors.Request + clauseData.data)
        // 获取光标所在位置
        let length = this.$refs.myQuillEditor.quill.selection.savedRange.index;
        // 调整光标到最后
        quill.setSelection(length + 2)

      } else {
        this.$message.error('图片插入失败')
      }
    }}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值