前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >vue中使用富文本编辑器(wangeditor)

vue中使用富文本编辑器(wangeditor)

作者头像
用户4344670
发布2020-04-02 14:46:19
7620
发布2020-04-02 14:46:19
举报
文章被收录于专栏:vue的实战vue的实战
代码语言:javascript
复制
<template>
  <div class="subcontainer">


    <!-- de -->

    <div class="editor" id="editor" ref="editor"></div>
    <div class="a-btn">
      <a href="javascript:void(0)">提交</a>
    </div>
  </div>
</template>

<script>
import pcSet from "@/components/pcSet/index";
import appSet from "@/components/appSet/index";

import E from "wangeditor";

export default {
  data() {
    return {
      activeName: "first",
      txt: {
        text: "9090"
      },

      editor: "" // 存放实例化的wangEditor对象,在多个方法中使用
    };
  },
  components: {
    pcSet,
    appSet
  },

  mounted() {
    this.editor = new E("#editor"); //new即可

    this.editor.customConfig.uploadImgShowBase64 = false; // base 64 存储图片
  this.editor.customConfig.uploadImgServer =
      ' common.requestUrl '+ "/file/upload/1?type=1&fn=educiot.png"; // 配置服务器端地址
    this.editor.customConfig.uploadImgHeaders = {}; // 自定义 header
    this.editor.customConfig.uploadFileName = "file"; // 后端接受上传文件的参数名
    this.editor.customConfig.uploadImgMaxSize = 10 * 1024 * 1024; // 将图片大小限制为 10M
    this.editor.customConfig.uploadImgMaxLength = 6; // 限制一次最多上传 3 张图片
    this.editor.customConfig.uploadImgTimeout = 3 * 60 * 1000; // 设置超时时间
    //下面的为一些配置参数,默认全部都有,我们需要那些留下那些即可
    this.editor.customConfig.menus = [
      "head", // 标题
      "bold", // 粗体
      "fontSize", // 字号
      "fontName", // 字体
      "italic", // 斜体
      "underline", // 下划线
      "strikeThrough", // 删除线
      "foreColor", // 文字颜色
      "backColor", // 背景颜色
      "link", // 插入链接
      "list", // 列表
      "justify", // 对齐方式
      // 'quote',  // 引用
      "emoticon", // 表情
      "image", // 插入图片
      "table", // 表格
      "video", // 插入视频
      "code", // 插入代码
      "undo", // 撤销
      "redo" // 重复
    ];
    //聚焦时候函数
    this.editor.customConfig.onfocus = function() {
      //console.log("onfocus")
    };
    //失焦时候函数
    this.editor.customConfig.onblur = function() {
      //console.log("onblur")
    };
    //change事件,当富文本编辑器内容发生变化时便会触发此函数
    this.editor.customConfig.onchange = function(text) {
      console.log(text);
    };
    this.editor.create(); //以上配置完成之后调用其create()方法进行创建
    this.editor.txt.html("8222 "); //创建完成之后的默认内容
    //点击事件,拿到富文本编辑器里面的值
    $(".a-btn a").on("click", () => {
      //富文本编辑器里面的内容我们可以输出为html(布局)格式,也可以输出位text(文本)格式
      console.log(this.editor.txt.text());
      console.log(this.editor.txt.html());
      //this.editor.change && this.editor.change();
    });
  },

  methods: {
    handleClick(tab, event) {
      console.log(tab, event);
    }
  }
};
</script>

<style lang="less" scoped>
.subcontainer {
  height: 100%;
  width: 100%;
  .tabs {
    padding: 20px 0;
  }
}

.editor {
  width: 100%;
  height: 300px;
  margin-bottom: 40px;
}
.a-btn {
  padding-bottom: 80px;
}
.a-btn a {
  display: block;
  color: #fff;
  font-size: 16px;
  line-height: 30px;
  width: 100px;
  text-align: center;
  float: right;
  background: dodgerblue;
}
</style>
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档