Vue富文本

11 篇文章 0 订阅

Vue富文本

1.wangEditor

感觉不是很美观,但是基本功能还是有的

官网:http://www.wangeditor.com/index.html

1.1如果使用了脚手架,安装了node,下载该插件

npm i wangeditor -S

1.2在页面引用,直接上代码了

<template>
  <div id="wangeditor">
    <div ref="editorElem" style="text-align:left;"></div>
    <el-button @click="handleConsole">尝试</el-button>
     <div v-html="editorContent"></div>
  </div>
</template>

<script>
import E from "wangeditor";
export default {
  name: '',

   data() {
    return {
      editor: null,
      editorContent: ''
    };
  },
  
 
  methods: {
      
        handleConsole:function(){
          console.log(this.editorContent)
      }

  },
  mounted(){
     this.editor = new E(this.$refs.editorElem);
    // 编辑器的事件,每次改变会获取其html内容
      this.editor.customConfig.onchange = html => {
      this.editorContent = html;
     
    };  
    this.editor.customConfig.menus = [
      // 菜单配置
      'head', // 标题
      'bold', // 粗体
      'fontSize', // 字号
      'fontName', // 字体
      'italic', // 斜体
      'underline', // 下划线
      'strikeThrough', // 删除线
      'foreColor', // 文字颜色
      'backColor', // 背景颜色
      'link', // 插入链接
      'list', // 列表
      'justify', // 对齐方式
      'quote', // 引用
      'emoticon', // 表情
      'image', // 插入图片
      'table', // 表格
      'code', // 插入代码
      'undo', // 撤销
      'redo' // 重复
    ];
    this.editor.customConfig.uploadImgShowBase64 = true// 使用 base64 保存图片
    // this.editor.customConfig.uploadImgServer = '/upload' 这是上传图片到服务器
    this.editor.create(); // 创建富文本实例  
    },
}
</script>

<style scoped>

</style>

效果图

在这里插入图片描述

1.3如果没有用脚手架

<div id="editor"></div>
 <script type="text/javascript" src="https://unpkg.com/wangeditor/release/wangEditor.min.js"></script>
   <script type="text/javascript">
      var E = window.wangEditor
      var editor = new E('#editor')
  // 或者 var editor = new E( document.getElementById('editor') )
  editor.create()
</script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值