How to introduce ueditor and node background configuration using vue
This article mainly introduces the detailed explanation of the introduction of ueditor and node background configuration in vue. Now I will share it with you and give you a reference.
Recently, a customer of the company wanted to use our company's products. He had a lot of requirements for a rich text editor in his backend management. He initially planned to use Quill, but found that Quill could not meet his needs at all. After researching the rich text editors on the market, it seems that only Baidu’s ueditor is left. Although it's ugly~~~, it doesn't matter. The government website and this effect are more
vue introduces ueditor
Steps
Baidu ueditor download, any version is fine (this article takes the PHP version as an example), if you don’t need particularly comprehensive functions, you can consider UM
Place the corresponding folder in In static
Modify ueditor.confg.js referenced by the front-end vue part and set the path window.UEDITOR_HOME_URL = "/static/utf8-php/"
window.UEDITOR_HOME_URL = "/static/utf8-php/" var URL = window.UEDITOR_HOME_URL || getUEBasePath(); /** * 配置项主体。注意,此处所有涉及到路径的配置别遗漏URL变量。 */ window.UEDITOR_CONFIG = { //为编辑器实例添加一个路径,这个不能被注释 UEDITOR_HOME_URL: URL // 服务器统一请求接口路径 , serverUrl: "http://localhost:3000/ueditor/ue" // ............ 下面忽略................
When writing vue files, I have configured static into the path of webpack. I can change it accordingly. The various methods in ueditor can be found in the index.html of the Baidu ueditor package I downloaded.
<template> <p class="hello"> <script id="editor" type="text/plain"></script> <button @click="show">你敢点一下吗?</button> </p> </template> <script> export default { name: 'HelloWorld', data () { return { editor: null } }, methods: { show () { console.log(this.editor.getContent()) } }, mounted () { require('static/utf8-php/ueditor.config.js') require('static/utf8-php/ueditor.all.min.js') require('static/utf8-php/lang/zh-cn/zh-cn.js') require('static/utf8-php/ueditor.parse.min.js') this.editor = window.UE.getEditor('editor') }, destroyed () { this.editor.destroy() } } </script>
Note
The path in step 3 must have the last "/"
-
The serverUrl in step 3 is written as the corresponding server address
node back-end processing
express implementation
Someone on the Internet has already implemented the express version. Those who use express are lucky. However, it cannot be used directly when I use it directly. ": unexcepected" is reported in the browser. I changed his code so that it does not redirect when returning the configuration, but directly returns a jsonp and jsonp content. Set it to config.json under the php file in Baidu's ueditor package. Remember to use regular expressions or directly remove the comments by hand. There are no comments in json.
At this time, you may find that no error is reported, but the image upload error occurs and a 404 is reported. In fact, the image has been uploaded successfully, but it is not loaded correctly, because the returned path is only the path, not the complete URL, and the request will be made to the front-end service domain. (e.g. "http://localhost:8080/**"). At this time, modify "imageUrlPrefix" in config.json: "http://localhost:3000" to complete the image path. Solve the cross-domain problem yourself -----
res.jsonp(config.json)
Add imageUrlPrefix to config.json Backend domain
koa implementation
This is a relatively sophisticated library, and the generator writing method will be removed in v3. The generator is now It is gradually not supported, so use async writing method. I mainly use the await-busboy library to implement file processing.
Implementing Judgment
const ActionType = ctx.query.action // 当ActionType为config时返回与express中一样的json // 当为uploadimage或uploadfile时处理 处理上传 const parse = require('await-busboy') const parts = parse(ctx) let part, stream, tmp_name, file_path, filename while ((part = await parts)) { if (part.length) { // 此处解析到form的fields console.log({ key: part[0], value: part[1] }) } else { // 此处解析到文件并以可读流形式返回,通过nodejs官方API存储 if(ActionType === 'uploadimage' && img_type.indexOf(path.extname(part.filename)) >= 0 ){ filename = 'pic_'+ (new Date()).getTime() + '_' + part.filename file_path = path.join(img_path, filename) } else if (ActionType === 'uploadfile'){ filename = 'file_'+(new Date()).getTime()+'_'+part.filename file_path = path.join(files_path, filename) } stream = fs.createWriteStream(path.join(static_path,file_path)) part.pipe(stream) tmp_name = part.filename } // 返回json要引用koa-jsonp哦~~
The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.
Related articles:
Use webpack to handle the problem of excessively large bundle.js files
How to fill in the default avatar in javascript
6 types of regular expressions in JavaScript (detailed tutorial)
The above is the detailed content of How to introduce ueditor and node background configuration using vue. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Node.js can be used as a backend framework as it offers features such as high performance, scalability, cross-platform support, rich ecosystem, and ease of development.

To connect to a MySQL database, you need to follow these steps: Install the mysql2 driver. Use mysql2.createConnection() to create a connection object that contains the host address, port, username, password, and database name. Use connection.query() to perform queries. Finally use connection.end() to end the connection.

The following global variables exist in Node.js: Global object: global Core module: process, console, require Runtime environment variables: __dirname, __filename, __line, __column Constants: undefined, null, NaN, Infinity, -Infinity

There are two npm-related files in the Node.js installation directory: npm and npm.cmd. The differences are as follows: different extensions: npm is an executable file, and npm.cmd is a command window shortcut. Windows users: npm.cmd can be used from the command prompt, npm can only be run from the command line. Compatibility: npm.cmd is specific to Windows systems, npm is available cross-platform. Usage recommendations: Windows users use npm.cmd, other operating systems use npm.

The main differences between Node.js and Java are design and features: Event-driven vs. thread-driven: Node.js is event-driven and Java is thread-driven. Single-threaded vs. multi-threaded: Node.js uses a single-threaded event loop, and Java uses a multi-threaded architecture. Runtime environment: Node.js runs on the V8 JavaScript engine, while Java runs on the JVM. Syntax: Node.js uses JavaScript syntax, while Java uses Java syntax. Purpose: Node.js is suitable for I/O-intensive tasks, while Java is suitable for large enterprise applications.

Yes, Node.js is a backend development language. It is used for back-end development, including handling server-side business logic, managing database connections, and providing APIs.

Server deployment steps for a Node.js project: Prepare the deployment environment: obtain server access, install Node.js, set up a Git repository. Build the application: Use npm run build to generate deployable code and dependencies. Upload code to the server: via Git or File Transfer Protocol. Install dependencies: SSH into the server and use npm install to install application dependencies. Start the application: Use a command such as node index.js to start the application, or use a process manager such as pm2. Configure a reverse proxy (optional): Use a reverse proxy such as Nginx or Apache to route traffic to your application

Yes, Node.js can be used for front-end development, and key advantages include high performance, rich ecosystem, and cross-platform compatibility. Considerations to consider are learning curve, tool support, and small community size.
