vue + mavon-editor编辑器

20 篇文章 0 订阅

vue + mavon-editor编辑器

我个人使用过 quill-editor编辑器mavon-editor编辑器
这个编辑器的优点还挺多的,但我个人的观点预览功能很棒

如果后续想了解 quill-editor的话 我也会出这个教程

步骤一、下载依赖
 npm install mavon-editor --save
步骤二、 在main.js中引入
 
    import Vue from 'vue'
    import mavonEditor from 'mavon-editor'
    import 'mavon-editor/dist/css/index.css'
 
    Vue.use(mavonEditor)
步骤三、页面的使用

1.html部分

<mavon-editor
   v-model="form.content"
   :toolbars="toolbars"
   :imageFilter="uploadBefore"
   placeholder="从这里开始编辑正文...."
   @imgAdd="$imgAdd"
   ref="md"
   @save="saveMavon"
/>

2.script部分

// 数据部分得 配置项   这块我是封装成一个.js文件了 
toolbars:{
  bold: true, // 粗体
  italic: true, // 斜体
  header: true, // 标题
  underline: true, // 下划线
  strikethrough: true, // 中划线
  mark: true, // 标记
  superscript: true, // 上角标
  subscript: true, // 下角标
  quote: true, // 引用
  ol: true, // 有序列表
  ul: true, // 无序列表
  link: true, // 链接
  imagelink: true, // 图片链接
  code: true, // code
  table: true, // 表格
  fullscreen: true, // 全屏编辑
  readmodel: true, // 沉浸式阅读
  htmlcode: true, // 展示html源码
  help: true, // 帮助
  /* 1.3.5 */
  undo: true, // 上一步
  redo: true, // 下一步
  trash: true, // 清空
  save: true, // 保存(触发events中的save事件)
  /* 1.4.2 */
  navigation: true, // 导航目录
  /* 2.1.8 */
  alignleft: true, // 左对齐
  aligncenter: true, // 居中
  alignright: true, // 右对齐
  /* 2.2.1 */
  subfield: true, // 单双栏模式
  preview: true // 预览
}
// 对应的方法部分 (上传图片 保存的一些处理)

// 将图片上传到服务器,返回地址替换到md中
    async $imgAdd(pos, $file) {
      this.saving = true;
      console.log(pos, $file);
      var formData = new FormData();
      formData.append("file", $file);
      uploadImage(formData).then(res => {
        if (res.code == 200) {
          var url = res.url;
          // 让它插入到相应的部分
          this.$refs.md.$img2Url(pos, url);
          this.saving = false;
        }
      });
    },
    
// 点击保存
saveMavon(value, render) {
      console.log("this is render" + render);
      console.log("this is value" + value);
      console.log(this.$refs.md.d_render);
 },

// 限制图片的大小
    uploadBefore(f) {
      if (f.size > 2016324) {
        this.$message.error("图片限制大小为2M");
        return false;
      } else {
        return true;
      }
    },

如果对 quill-editor 感兴趣的 那下次再见啦

📢没了,结束了,如有错误,欢迎留言.如有问题,不吝赐教。
📢如果此篇博文对您有帮助,还请动动小手点赞 👍 收藏 ⭐留言 📝呐~,谢谢 ~ ~

  • 4
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值