我是靠谱客的博主 过时枫叶,最近开发中收集的这篇文章主要介绍解决wangeditor+oss 批量上传图片顺序不对问题,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

两个组件
“wangeditor”: “^4.7.5”,
“ali-oss”: “^6.7.0”
放入package.json
cnpm install

 <div id="weditor"></div>
import E from 'wangeditor'
import OSS from 'ali-oss'

export default {
 data() {
      return {
      	editor: '',
      }
	},
	mounted() {
	      this.editor = new E('#weditor')
	      this.configEditor()
	      this.editor.create()
	    },
	method:{
	 configEditor() {
	        // 设置编辑区域高度为 500px
	        this.editor.config.height = 800
	        // 配置OSS
	        let client = new OSS({
	          region: 'region',
	          accessKeyId: 'accessKeyId',
	          accessKeySecret: 'accessKeySecret',
	          bucket: 'bucket'
	        })
	        let this_ = this
	        this.editor.config.customUploadImg = async function(resultFiles, insertImgFn) {
	          // resultFiles 是 input 中选中的文件列表
	          // insertImgFn 是获取图片 url 后,插入到编辑器的方法
	          // 重点在这里
	          // 首先wangeditor文档用的是异步的方式向编辑器插入图片,这是不行的,要改同步
	          // resultFiles 如果用forEach() 遍历也是异步的,改成for循环
	          for (let i =0;i<resultFiles.length;i++){
	            let res = await client.put(this_.guid(),resultFiles[i])
	            insertImgFn(res.url)
	          }
	
	        }
	       
	      },
	},
}


最后

以上就是过时枫叶为你收集整理的解决wangeditor+oss 批量上传图片顺序不对问题的全部内容,希望文章能够帮你解决解决wangeditor+oss 批量上传图片顺序不对问题所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(78)

评论列表共有 0 条评论

立即
投稿
返回
顶部