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!

JavaScript is widely used in websites, mobile applications, desktop applications and server-side programming. 1) In website development, JavaScript operates DOM together with HTML and CSS to achieve dynamic effects and supports frameworks such as jQuery and React. 2) Through ReactNative and Ionic, JavaScript is used to develop cross-platform mobile applications. 3) The Electron framework enables JavaScript to build desktop applications. 4) Node.js allows JavaScript to run on the server side and supports high concurrent requests.

Python is more suitable for data science and automation, while JavaScript is more suitable for front-end and full-stack development. 1. Python performs well in data science and machine learning, using libraries such as NumPy and Pandas for data processing and modeling. 2. Python is concise and efficient in automation and scripting. 3. JavaScript is indispensable in front-end development and is used to build dynamic web pages and single-page applications. 4. JavaScript plays a role in back-end development through Node.js and supports full-stack development.

C and C play a vital role in the JavaScript engine, mainly used to implement interpreters and JIT compilers. 1) C is used to parse JavaScript source code and generate an abstract syntax tree. 2) C is responsible for generating and executing bytecode. 3) C implements the JIT compiler, optimizes and compiles hot-spot code at runtime, and significantly improves the execution efficiency of JavaScript.

JavaScript's application in the real world includes front-end and back-end development. 1) Display front-end applications by building a TODO list application, involving DOM operations and event processing. 2) Build RESTfulAPI through Node.js and Express to demonstrate back-end applications.

The main uses of JavaScript in web development include client interaction, form verification and asynchronous communication. 1) Dynamic content update and user interaction through DOM operations; 2) Client verification is carried out before the user submits data to improve the user experience; 3) Refreshless communication with the server is achieved through AJAX technology.

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.


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

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version
Visual web development tools

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

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools