vue“欺骗”ueditor,实现图片上传

一、环境介绍

@vue/cli 4.3.1

webpack 4.43.0

ueditor1.4.3.3 jsp版

二、springboot集成ueditor,实现分布式图片上传

参考我的另一篇博客,《微服务迁移记(五):WEB层搭建(5)-集成ueditor编辑器,伪分布式图片上传

配置完成后,有一个http://192.168.43.89:3000/ueconfig配置接口提供外网访问。

三、vue2.0 集成ueditor

1. 下载ueditor源码,放入/public/static目录(网上很多说放入public就行了,实际代码写死了是找/public/static目录的UEditor),并配置ueditor.config.js

// 服务器统一请求接口路径

, serverUrl: "http://192.168.43.89:3000/ueconfig"

 

2. npm i vue-ueditor-wrap 安装插件

3. 引入插件

复制代码
import VueEditorWrap from 'vue-ueditor-wrap'
.....
data() {
  return {
   ueconfig: {
                toolbars: [
                    ['fullscreen', 'undo', 'redo', 'bold','italic', 'underline', 'fontborder', 'strikethrough', 'removeformat','forecolor','backcolor','fontfamily', 'fontsize','customstyle', 'paragraph',
                     '|','rowspacingtop', 'rowspacingbottom', 'lineheight', '|','justifyleft', 'justifycenter', 'justifyright', 'justifyjustify','insertimage'
                    ]
                ]
            }
  }
}
components: {
        VueEditorWrap
    },
.....
复制代码
<VueEditorWrap v-model="comment_content" :config="ueconfig" />

前台预览后,出现错误,造成图片上传功能不可使用,其他编辑功能正常。

Cross-Origin Read Blocking (CORB) blocked cross-origin response http://192.168.43.89:3000/ueconfig?action=config&callback=bd__editor__hfkwb3

 

究其原因主要是跨域,通过访问http://192.168.43.89:3000/ueconfig?action=config&callback=bd__editor__hfkwb3,可以看到ueditor已经进行了jsonp的跨域处理,但始终无法通过。决定伪装访问ueconfig



四、本地代理访问ueconfig URL

在vue.config.js中增加如下配置项:
复制代码
module.exports = {
    devServer: {
        proxy: {'/iot/ue': {
                target: 'http://192.168.43.89:3000/ueconfig',
                changeOrigin: true,
                pathRewrite: {
                    '^/iot/ue': ''
                }
            }
        }
    }
复制代码

配置ue的ServerURL地址为:

复制代码
ueconfig: {
                serverUrl: '/iot/ue',
                toolbars: [
                    ['fullscreen', 'undo', 'redo', 'bold','italic', 'underline', 'fontborder', 'strikethrough', 'removeformat','forecolor','backcolor','fontfamily', 'fontsize','customstyle', 'paragraph',
                     '|','rowspacingtop', 'rowspacingbottom', 'lineheight', '|','justifyleft', 'justifycenter', 'justifyright', 'justifyjustify','insertimage'
                    ]
                ]
            }
复制代码

 

相当于告诉ue,我是local访问的,并没有跨域,ue居然就这么相信了!

再次访问,成功上传图片

 

posted on   zhouyu  阅读(922)  评论(0编辑  收藏  举报

编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· .NET周刊【3月第1期 2025-03-02】
· [AI/GPT/综述] AI Agent的设计模式综述

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示