nodejs+mongodb+vue前后台配置ueditor
笔者在做一个个人博客项目的时候需要一个富文本框输入组件与后台进行交互,但是官方配置里面没有关于nodejs的,于是自己查阅资料研究了一下,最后终于应用到了系统中。
一、后台配置
首先是找到了这个项目:https://github.com/netpi/ueditor,可以通过他开源的代码将ueditor应用的node上面,大概方法如下:
1.先安装依赖:
npm install ueditor --save
2. 配置Node设置
//引入接口文件
const api = require('./api');
//引入文件模块
const fs = require('fs');
//引入处理路径模块
const path = require('path');
//引入处理post数据模块
var bodyParser = require('body-parser'); //引入express
const express = require('express');
const app = express();
//引入ueditor
const ueditor = require("ueditor") // parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false })) //更改限定大小
app.use(bodyParser.json({ limit: '50mb' }));
app.use(bodyParser.urlencoded({ limit: '50mb', extended: true }));
// parse application/json
app.use(bodyParser.json())
app.use(api) app.use("/ueditor/ue", ueditor(path.join(__dirname, 'public'), function(req, res, next) {
//客户端上传文件设置
var imgDir = '/img/ueditor/'
var ActionType = req.query.action;
if (ActionType === 'uploadimage' || ActionType === 'uploadfile' || ActionType === 'uploadvideo') {
var file_url = imgDir; //默认图片上传地址
/*其他上传格式的地址*/
if (ActionType === 'uploadfile') {
file_url = '/file/ueditor/'; //附件
}
if (ActionType === 'uploadvideo') {
file_url = '/video/ueditor/'; //视频
}
res.ue_up(file_url); //你只要输入要保存的地址 。保存操作交给ueditor来做
res.setHeader('Content-Type', 'text/html');
}
// 客户端发起图片列表请求
else if (req.query.action === 'listimage') {
var dir_url = imgDir;
res.ue_list(dir_url); // 客户端会列出 dir_url 目录下的所有图片
}
// 客户端发起其它请求
else {
// console.log('config.json')
res.setHeader('Content-Type', 'application/json');
res.redirect('../nodejs/config.json');
}
})); //处理静态文件 todo
// 访问静态资源文件 这里是访问所有dist目录下的静态资源文件
app.use(express.static(path.resolve(__dirname, 'public/')))
app.use('/ueditor', function(req, res) {
res.render('views/');
}); //监听8888端口
app.listen(8888);
console.log('sucess listen......')
这里需要注意的是因为已经require了ueditor,所以该插件已经安装到了node_module内,所以不需要再拷贝额外的文件了,只需要需要在这个目录下面新建public文件夹存放返回给后台的数据,另外,还需要引入配置文件config.json
二、前台配置
vue的前台配置需要下载ueditor的文件放在目录中,我将其放在了static文件夹中,在vue入口文件中引入ueditor的文件:
import '../static/UE/ueditor.config.js'
import '../static/UE/ueditor.all.min.js'
import '../static/UE/lang/zh-cn/zh-cn.js'
import '../static/UE/ueditor.parse.min.js'
值得一提的是需要将ueditor.config.js文件中的目录配置为放置该插件的目录:
window.UEDITOR_HOME_URL = "/static/UE/"
然后在组件中配置好就可以了
我的UE.vue组件:
<template>
<script :id=id type="text/plain"></script>
</template> <script>
export default {
name: 'UE',
data () {
return {
editor: null
}
},
props: {
defaultMsg: {
type: String
},
config: {
type: Object
},
id: {
type: String
},
},
mounted() {
const _this = this;
this.editor = UE.getEditor(this.id, this.config); // 初始化UE
this.editor.addListener("ready", function () {
_this.editor.setContent(_this.defaultMsg); // 确保UE加载完成后,放入内容。
});
},
methods: {
getUEContent() { // 获取内容方法
return this.editor.getContent()
}
},
destroyed() {
this.editor.destroy();
}
}
</script>
引入方式:
<UE :defaultMsg=defaultMsg :config=config :id=ue1 ref="ue"></UE>
data() {
return {
defaultMsg: "",
image: "",
config: {
initialFrameWidth: null,
initialFrameHeight: 350
},
ue1: "ue1"
};
},
就可以成功配置好ueditor的基本功能了
三、前后台请求代理
在vue dev环境下可以设置webpack的proxyTable将后端请求代理转发,就可以轻松调试文件上传功能了,同理,vue build之后的文件则需要用Node将静态文件代理到和后端同一个端口上才可以请求后台端口
篇幅有限,文章可能讲述的不太清晰,具体的可以看我这个项目的代码:https://github.com/cheer4chai/myBlog
nodejs+mongodb+vue前后台配置ueditor的更多相关文章
- NodeJS,MongoDB,Vue,VSCode 集成学习
NodeJS,MongoDB,Vue,VSCode 集成学习 开源项目地址:http://www.mangdot.com
- 【前端】Ubuntu16下nodejs+npm+vue环境配置
笔者最近在学习vue.js,不过一直都是在runoob上面各种尝试.今天笔者在本机(Ubuntu16.04)尝试部署了nodejs+npm+vue开发环境,接下来将尽可能详细的讲述安装过程,帮助新人少 ...
- vue中使用Ueditor编辑器
一. 下载包: 从Ueditor的官网下载1.4.3.3jsp版本的Ueditor编辑器,官网地址为: http://ueditor.baidu.com/website/ 下载解压后会得到如果下文 ...
- vue中使用Ueditor编辑器 -- 1
一. 下载包: 从Ueditor的官网下载1.4.3.3jsp版本的Ueditor编辑器,官网地址为:http://ueditor.baidu.com/website/download.html ...
- nodejs学习笔记三——nodejs使用富文本插件ueditor
在做自己的nodejs项目的时候遇到需要使用ueditor.原来下载的是ueditor的jsp版本.目录如下 在ueditor.config.js中有配置服务器home路径(这个home路径能找到u ...
- react+react-router+react-redux+nodejs+mongodb项目
一个实际项目(OA系统)中的部分功能.这个demo中引入了数据库,数据库使用了mongodb.安装mongodb才能运行完整的功能.要看完整的项目可以移步我的github 技术栈 React v15. ...
- vue环境配置 vue-cli脚手架
vue 环境配置步骤: 第一步: 在官网下载node,Node 下载地址 http://nodejs.cn/ 并安装node.检测node是否安装成功, 按 “windows+r” 进入cmd命令 ...
- linux安装nodejs运行vue程序
linux安装nodejs运行vue程序 1.与node官网下载安装包 https://nodejs.org/zh-cn/download/ 6.上传到服务器,并解压 tar -xvf node-v1 ...
- vue环境配置脚手架环境搭建vue工程目录
首先在初始化一个vue项目之前,我们需要下载node.js,并且安装! 下载地址: nodejs.cn/download 安装完成之后,windows+r 运行命令 cmd 输入node -v 检 ...
随机推荐
- C语言之scanf
#include<stdio.h>int main(){int num;int a,b,c,result,d,result1;scanf("int%d",&nu ...
- listviewMyAdapter
import android.content.Context;import android.graphics.Bitmap;import android.graphics.BitmapFactory; ...
- 大数据学习(1)Hadoop安装
集群架构 Hadoop的安装其实就是HDFS和YARN集群的配置,从下面的架构图可以看出,HDFS的每一个DataNode都需要配置NameNode的位置.同理YARN中的每一个NodeManager ...
- 1267 - Illegal mix of collations (gbk_chinese_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '=' | 1267 - Illegal mix of collations (gbk_chinese_ci,IMPLICIT) and (Latin,COERCIBL)
select * FROM information_schema.columns WHERE table_schema = "databaseName" and collation ...
- Object-C中release的机制问题
今天写了例如以下的一段代码: for (NSInteger i = 0; i < 10000000; i++) { UIView * v = [[UIView alloc] init]; [v ...
- UVA 1426 - Discrete Square Roots(数论)
UVA 1426 - Discrete Square Roots 题目链接 题意:给定X, N. R.要求r2≡x (mod n) (1 <= r < n)的全部解.R为一个已知解 思路: ...
- xml文档读取-SAX
由于dom采用的是将xml文档加载入内存进行处理的方式,如果xml文档较大,则会导致加载时间过长,效率降低的情况,因此,sun公司在JAXP中又添加了对SAX的支持: SAX,全称Simple API ...
- Git(二)Git几个区的关系与Git和GitHub的关联
前言 前面只是大概的介绍了一点基础的东西,接下来会更加深入的去了解一下Git. 一.Git的工作区.暂存区和版本库之间的区别和联系 1)工作区 在PC中能看得到的创建的一个管理仓库的目录.比如目录下G ...
- 在Laravel中使用swoole来取代nginx作为http服务器
1.是什么限制Laravel框架的速度? Laravel框架启动的时候需要加载很多文件,再加上其出了名的生态环境好,所以在开发过程中我们就会发现有非常多的已经造好的轮子,这也就使得Laravel的一次 ...
- CentOS 6.5 安装MySQL过程
使用软件的版本 CentOS 6.5 mysql-5.5.22.tar.gz cmake-2.8.6.tar.gz 准备工作 解压安装mysql之前把关于mysql软件包卸载,以免程序冲突,端口冲突. ...