三个步骤: 1、设置跨域请求: header('content-type:text/html;charset=utf-8'); header('Access-Control-Allow-Origin: *'); 2、修改源码wangEditor.js(非min版): // 跨域上传时,传cookie 将源码:(在6768行) xhr.withCredentials = editor.config.withCredentials || true; 修改为: xhr.withCredentials = editor.config.withCredentials && true; (至此可以正常跨域上传) 3、返回路径报错,插入失败: 将[定义load函数]方法,(在6543~6573行)注释 修改为(如果是json数据): // -------- 定义load函数 -------- // editor.config.uploadImgFns.onload = function (result, xhr) { //判断服务器返回状态 if ( xhr.status !== 200 ) { console.warn('上传失败:' + xhr.status); self.$message.error('图片上传失败,请重试') } else { result = JSON.parse(result)
wangEditor 跨域上传解决方案之一
最新推荐文章于 2024-04-04 21:00:48 发布