vue使用富文本编辑器上传图片:

我是用的是wangEditor 富文本编辑器 demo:http://www.wangeditor.com/
1).安装依赖:npm install wangeditor
2).我自己是创建了一个组件这样再用到的时候可以直接调用(可能有更简单的方法)

<template lang="html"><div class="editor"><div ref="toolbar" class="toolbar"></div><div ref="editor" class="text"></div></div>
</template><script>import E from 'wangeditor'let editor=nullexport default {name: 'Editorbar',data () {return {info_: null}},model: {prop: 'value',event: 'change'},props: {value: {type: String,default: ''},isClear: {type: Boolean,default: false}},watch: {isClear (val) {// 触发清除文本域内容if (val) {editor.txt.clear()this.info_ = null}},value (val) {// 使用 v-model 时,设置初始值
        editor.txt.html(val)}},mounted () {this.seteditor()},methods: {seteditor () {editor = new E(this.$refs.toolbar, this.$refs.editor)editor.customConfig.uploadImgShowBase64 = true // base 64 存储图片
        editor.customConfig.uploadImgServer = 'http://47.106.198.122/api/CanteenAdmin/CanteenManagement/UploadImage'// 配置服务器端地址
        editor.customConfig.uploadImgHeaders = {  'token':sessionStorage.getItem('token')    }// 自定义 header
        editor.customConfig.uploadFileName = 'image' // 后端接受上传文件的参数名
        editor.customConfig.uploadImgMaxSize = 2 * 1024 * 1024 // 将图片大小限制为 2M
        editor.customConfig.uploadImgMaxLength = 6 // 限制一次最多上传 3 张图片
        editor.customConfig.uploadImgTimeout = 3 * 60 * 1000 // 设置超时时间// this.editor.customConfig.uploadParams = {formFile:'2'};// 配置菜单
        editor.customConfig.menus = ['bold', // 粗体'underline', // 下划线'link', // 插入链接'quote', // 引用'emoticon', // 表情'image', // 插入图片'table', // 表格'code', // 插入代码
]editor.customConfig.uploadImgHooks = {fail: (xhr, editor, result) => {// 插入图片失败回调
          },success: (xhr, editor, result) => {// 图片上传成功回调//
            // let imgUrl = result.data;// insertImg(imgUrl)
          },timeout: (xhr, editor) => {// 网络超时的回调
          },error: (xhr, editor) => {console.log(editor)// 图片上传错误的回调
          },customInsert: (insertImg, result, editor) => {// 图片上传成功,插入图片的回调
            console.log(result);// if(result.code == 200){var url = result.data;insertImg(url)//将内容插入到富文本中// console.log(insertImg(url)+"DFDF")// console.log(data+"dsfd")// }
          }};editor.customConfig.onchange = (html) => {this.info_ = html // 绑定当前逐渐地值this.$emit('change', this.info_) // 将内容同步到父组件中
          console.log(this.info_ )};// 创建富文本编辑器
        editor.create()}}}
</script><style lang="css">.editor {width: 80%;margin-left: 4%;}.toolbar {border: 1px solid #ccc;}.w-e-menu{z-index:1 !important;}.text {width:100%;border: 1px solid #ccc;height: 300px;}
</style>

editor.vue

<!--富文本编辑器--><div style="margin-top:2%;margin-left: 1%"><editor-bar v-model="zldata.info" :isClear="isClear"></editor-bar></div>js:
<script>
import EditorBar from './editor'export default {data: function () {return {isClear: false,zldata: {info:'',},}},components: {EditorBar},}</script>

调用

喜欢的给个赞吧!!!

转载于:https://www.cnblogs.com/M-miao/p/9838702.html

vue问题四:富文本编辑器上传图片相关推荐

  1. 关于Vue使用ueditor富文本编辑器上传图片

    1.使用的是vue-ueditor-wrap,前面操作网上都有,放到public下即可 2.ueditor上传图片会先请求服务器获取配置项,但是考虑我们的上传图片接口本身就有,后台那边也不想配合,只能 ...

  2. vue quill富文本编辑器上传图片遇到的坑

    在使用quill富文本编辑器上传图片的时候,很多地方都是成功的,但是唯有一处,上传图片总是失败,由此后端的朋友就说可以html标签转换成JSON字符串上传上去,展示的时候在转换回来,即可解决问题. 由 ...

  3. 富文本编辑器上传图片的功能

    今天,我们来讲一下富文本编辑器上传图片功能的操作.首先,在这里需要引入一个js插件 (config.js),在插件里面写下配置图片上传的路径. 接下来,既然要实现上传图片的功能,那我们就需要一个东西是 ...

  4. vue项目 vue-quill-editor富文本编辑器+图片上传

    目录 基础使用: 进阶版: 使用 el-upload 图片上传: 进阶版2.0: 可拖动调整图片大小: 基础使用: 富文本编辑器: 此方法得到的图片为base64编码,图片上传在下面. npm ins ...

  5. vue 是否有word编辑控件_GitHub - C84882428/editor-ui: vue集成 tinymce 富文本编辑器,增加导入 word 模板...

    editor-ui vue 集成 tinymce 富文本编辑器 自定义 tinymce 富文本编辑器, 在原来的编辑器中增加上传 word 模板 最终展示效果: 主要代码: 整体思路: 1,在编辑器原 ...

  6. vue使用百度富文本编辑器(ueditor)

    文章目录 vue使用百度富文本编辑器(ueditor) 1.进入官网或者github下载源码 2.使用grunt编译 4.安装`vue-ueditor-wrap` 5.组件中引入,自定义组件 6.后端 ...

  7. vue使用WangEditor富文本编辑器(批量上传图片到服务器)

    最近要写一个官网,但是这个官网要写成活的可配置的项目,于是要先写一后台管理系统,用来配置官网的菜单和页面,配置菜单自然是vue+ElementUI表格表单的增删改查,但是配置页面就要有排版.样式等等, ...

  8. 在Vue中使用Tinymce富文本编辑器+上传图片到七牛

    公司官网后台需要做一个上传新闻.公告的功能,自然而然就需要用到了富文本编辑器. UEditor.Simditor.wangEditor.CKEditor.TinyMCE.Quill,这是当前比较热门的 ...

  9. wangeditor html编辑,Vue整合wangEditor富文本编辑器

    最近在做项目时,客户有个发布新闻动态的功能,具体页面内容让客户自己编写,所以要选择富文本编辑器,这样用户体验好一点.网上有很多的富文本编辑器, 因为项目的功能并不是很复杂,所以选择了wangEdito ...

最新文章

  1. linux命令执行返回值(附错误对照表)
  2. 发现一个很好的工具——VNN
  3. Git_Eclipse:[3]Git初始化工程
  4. zigbee 端点描述符
  5. spring基于注解的声明式事务控制
  6. 装了这几个插件后,我不得不给 IDEA 上个防沉迷
  7. Jsp内置对象实验报告
  8. CNN--MINIST
  9. 重启tomcat服务器步骤
  10. 用R的igraph包来画蛋白质互作网络图 | PPI | protein protein interaction network | Cytoscape...
  11. 小程序 40163_微信小程序请求openid错误码40163
  12. 论文阅读:《Connectionist Temporal Classification: Labelling Unsegmented Sequence Data with Recurrent Neu》
  13. 有权最短路径问题:狄克斯特拉(Dijkstra)算法 Java 实现
  14. python中的请求方法_Python爬虫HTPP请求方法有哪些
  15. Spring的9处调用后置处理器
  16. osgEarth指北针
  17. 大数据开发是做什么的?怎样入门?
  18. hdu5594 ZYB's Prime
  19. 变形金刚2中的各个角色,及车型(带图)第一篇。
  20. React组件间信息传递方式

热门文章

  1. 在.net中加载dll的一种错误问题原因及处理
  2. ai/ml_您本周应阅读的有趣的AI / ML文章(8月15日)
  3. 朴素贝叶斯 半朴素贝叶斯_使用朴素贝叶斯和N-Gram的Twitter情绪分析
  4. 使用OpenCV和Python从图像中提取形状
  5. 国际人工智能算法与应用研讨会(WASA 2018)参会笔记
  6. 不是每个人都适合linux
  7. 学习笔记(一)(x264编码流程)
  8. Android Animation实现元素在屏幕上按照指定轨迹运动,以及出现NullPointerException的解决方案
  9. 在WinAVR中设置Makefile自动编译多个源文件
  10. Java面向对象入门