NodeJs的ueditor配置注意事项

本文介绍了解决UEditor中图片超出编辑器宽度的问题的方法,通过CSS样式限制图片最大宽度,并详细展示了如何配置服务端接口来支持UEditor的各种功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

图片:
在iframe.css加img{max-width:100%},解决上传图片超出编辑器宽度问题
在展示页面中需要在,包裹ueditor生成的html的元素中也加上:img{max-width:100%},解决图片过大又未设置宽度超出容器宽度问题


地址:
ueditor.config.js
1:UEDITOR_HOME_URL为当前ueditor的路径地址,eg: '/assets/plugins/ueditor/'
2:serverUrl为服务端设置的ueditor接口地址,eg: '/ueditor/ue'


服务端:
1:安装ueditor包
2:静态文件夹,如:public,下添加ueditor.config.json服务端配置文件
3:添加路由处理
app.use("/ueditor/ue", ueditor(path.join(__dirname, 'public'), function (req, res, next) {
    var ActionType = req.query.action;
    if (ActionType === 'uploadimage' || ActionType === 'uploadfile' || ActionType === 'uploadvideo') {
        var file_url = '/img/ueditor/';
        if (ActionType === 'uploadfile') {
            file_url = '/file/ueditor/';
        }
        if (ActionType === 'uploadvideo') {
            file_url = '/video/ueditor/';
        }
        res.ue_up(file_url);
        res.setHeader('Content-Type', 'text/html');
    }
    else if (ActionType === 'listimage') {
        var dir_url = '/images/ueditor/';
        res.ue_list(dir_url);
    }
    else {
        res.setHeader('Content-Type', 'application/json');
        res.redirect('/ueditor/ueditor.config.json')
    }

}));


若字数统计有误,修改源码:ueditor.all.js

getContentLength: function (ingoneHtml, tagNames) {
    var count = this.getContent(false,false,true).length;
    if (ingoneHtml) {
        tagNames = (tagNames || []).concat([ 'hr', 'img', 'iframe']);
        count = this.getContentTxt().replace(/[\t\r\n]+/g, '').length;
        for (var i = 0, ci; ci = tagNames[i++];) {
            count += this.document.getElementsByTagName(ci).length;
        }
    }
    //return count;
return count + 260;//修改为这},

PS D:\zhWork\202501gsykj\control_map> npm run serve > app@0.1.0 serve D:\zhWork\202501gsykj\control_map > vue-cli-service serve Browserslist: caniuse-lite is outdated. Please run: npx update-browserslist-db@latest Why you should do it regularly: https://github.com/browserslist/update-db#readme INFO Starting development server... [24%] building (3/381 modules) [24%] building (19/426 modules) [BABEL] Note: The code generator has deoptimised the styling of D:\zhWork\202501gsykj\control_map\node_modules\element-ui\lib\element-ui.common.js as it exceeds the max of[38%] building (486/800 modules) [BABEL] Note: The code generator has deoptimised the styling of D:\zhWork\202501gsykj\control_map\node_modules\lodash\lodash.js as it exceeds the max of 500KB. <--- Last few GCs ---> [4820:000001E7C4609C20] 54577 ms: Mark-sweep (reduce) 4088.9 (4101.7) -> 4088.5 (4102.7) MB, 495.5 / 0.0 ms (+ 0.1 ms in 323 steps since start of marking, biggest step 0.0 ms, walltime since start of marking 655 ms) (average mu = 0.590, current mu = 0[4820:000001E7C4609C20] 55203 ms: Mark-sweep (reduce) 4089.5 (4104.7) -> 4089.0 (4105.2) MB, 620.5 / 0.0 ms (average mu = 0.379, current mu = 0.008) allocation failure scavenge might not succeed <--- JS stacktrace ---> FATAL ERROR: MarkCompactCollector: young object promotion failed Allocation failed - JavaScript heap out of memory 1: 00007FF62825412F napi_wrap+133311 2: 00007FF6281EDD06 SSL_get_quiet_shutdown+63062 3: 00007FF6281EEB9D node::OnFatalError+301 4: 00007FF628AD19CE v8::Isolate::ReportExternalAllocationLimitReached+94 5: 00007FF628AB67BD v8::SharedArrayBuffer::Externalize+781 6: 00007FF62895FFCC v8::internal::Heap::EphemeronKeyWriteBarrierFromCode+1516 7: 00007FF62894AA4B v8::internal::NativeContextInferrer::Infer+59739 8: 00007FF62892FD1F v8::internal::MarkingWorklists::SwitchToContextSlow+56975 9: 00007FF628943A0B v8::internal::NativeContextInferrer::Infer+31003 10: 00007FF62893AAED v8::internal::MarkCompactCollector::EnsureSweepingCompleted+6285 11: 00007FF628942C5E v8::internal::NativeContextInferrer::Infer+27502 12: 00007FF628946CAB v8::internal::NativeContextInferrer::Infer+43963 13: 00007FF6289506A2 v8::internal::ItemParallelJob::Task::RunInternal+18 14: 00007FF628950631 v8::internal::ItemParallelJob::Run+641 15: 00007FF628923C93 v8::internal::MarkingWorklists::SwitchToContextSlow+7683 16: 00007FF62893AF9C v8::internal::MarkCompactCollector::EnsureSweepingCompleted+7484 17: 00007FF6289397D4 v8::internal::MarkCompactCollector::EnsureSweepingCompleted+1396 18: 00007FF628937348 v8::internal::MarkingWorklists::SwitchToContextSlow+87224 19: 00007FF628965DB1 v8::internal::Heap::LeftTrimFixedArray+929 20: 00007FF628967EA5 v8::internal::Heap::PageFlagsAreConsistent+789 21: 00007FF62895D0C1 v8::internal::Heap::CollectGarbage+2049 22: 00007FF62895B2C5 v8::internal::Heap::AllocateExternalBackingStore+1349 23: 00007FF628975155 v8::internal::GCIdleTimeHandler::ShouldDoContextDisposalMarkCompact+1029 24: 00007FF6289755A5 v8::internal::Factory::AllocateRaw+37 25: 00007FF628986DA6 v8::internal::FactoryBase<v8::internal::Factory>::AllocateRawArray+38 26: 00007FF628986EBF v8::internal::FactoryBase<v8::internal::Factory>::AllocateRawFixedArray+31 27: 00007FF6289769E1 v8::internal::Factory::CopyFixedArrayAndGrow+65 28: 00007FF62879F7E4 v8::internal::WeakArrayList::AddToEnd+3300 29: 00007FF6289ACC2A v8::internal::Isolate::CaptureSimpleStackTrace+1146 30: 00007FF6289AC971 v8::internal::Isolate::CaptureSimpleStackTrace+449 31: 00007FF6289AC0BD v8::internal::Isolate::CaptureAndSetSimpleStackTrace+45 32: 00007FF6289A28A0 v8::internal::MessageLocation::MessageLocation+3664 33: 00007FF6289A63BC v8::internal::MessageFormatter::Format+13100 34: 00007FF62897ADB6 v8::internal::Factory::NewError+134 35: 00007FF628984AF2 v8::internal::Factory::NewTypeError+162 36: 00007FF6289A6561 v8::internal::MessageHandler::MakeMessageObject+337 37: 00007FF6286ABF7C v8::internal::interpreter::JumpTableTargetOffsets::iterator::operator=+9596 38: 00007FF628B5CDFD v8::internal::SetupIsolateDelegate::SetupHeap+474253 39: 00007FF628AED1C9 v8::internal::SetupIsolateDelegate::SetupHeap+16473 40: 00007FF628AF2FC2 v8::internal::SetupIsolateDelegate::SetupHeap+40530 41: 0000010772004690 npm ERR! code ELIFECYCLE npm ERR! errno 134 npm ERR! app@0.1.0 serve: `vue-cli-service serve` npm ERR! Exit status 134 npm ERR! npm ERR! Failed at the app@0.1.0 serve script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! D:\softwareInstall\nvmInstall\nodejs\node_cache\_logs\2025-07-19T15_03_28_775Z-debug.log
最新发布
07-20
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值