开始一个Koa+mongodb项目(九)koa-ueditor的配置使用

一、安装

npm install koa2-ueditor --save 

二、github下载demo包

下载 koa2-ueditor的demo
下载地址:https://github.com/sealice/koa2-ueditor

==下载完成以后把官方例子中的public->ueditor 复制过来。

三、使用

使用简单,只需传一个静态目录参数。不传则默认是public
// 直接写路由
// 然后修改 web 端的 ueditor.config.js 配置 serverUrl 为对应路由地址
// serverUrl: “/editor/controller”

const router = require(‘koa-router’)()
const ueditor = require(‘koa2-ueditor’)

router.all(’/editor/controller’, ueditor(‘public’))

四、实现业务逻辑

可以修改 UEditor 配置,具体的参数请参考 UEditor 官方的 config.json
配置 koa2-ueditor 模块

// 需要传一个数组:静态目录和 UEditor 配置对象
// 比如要修改上传图片的类型、保存路径
router.all('/editor/controller', ueditor(['public', {
	"imageAllowFiles": [".png", ".jpg", ".jpeg"]
	"imagePathFormat": "/upload/ueditor/image/{yyyy}{mm}{dd}/{filename}"  // 保存为原文件名
}]))

五、实例化编辑器

var ue = UE.getEditor('editor'); 

编辑器放入内容
var ue= UE.getEditor(‘editor’);
ueditor.addListener(“ready”, function (){
ueditor.setContent({{@list.content}});

这里还有ueditor的插件,可供参考:
http://ueditor.baidu.com/website/thirdproject.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值