Home Web Front-end JS Tutorial Share an example tutorial on building a vue-cli project.

Share an example tutorial on building a vue-cli project.

Jun 25, 2017 am 09:53 AM
ie mock vue-cli Backstage build

The background mock is implemented in "Adding the Backend Mock Interface to the Project Built by Vue-cli", but the t data of the front-end post must be used in the mock's background interface to use the req receiving data event to obtain the data in the http protocol body. .

req.on('data', function(chunk){  //接收字节数据});

req.end('data', function(){  //转换||处理});

req.error('error', function(e){  //处理错误});
Copy after login

If the front-end needs to use cookies and the back-end needs to read them, then the headers of req must be obtained in the background mock interface, and the cookie string must be obtained from it, and it must be divided by itself Processing and so on.

Of course this is possible, but it is more troublesome. You have to do it yourself from receiving the data to converting it.

The project built by vue-cli uses express as the web framework of node.js, which supports rich middleware.

Corresponding to the above problems, there are body-parser and cookie-parser middleware that can easily extract the data and cookies in the body of the post into req.body and req.cookies objects for human use, which is very convenient.

Install middleware

npm install body-parser --save-dev

npm install cookie-parser --save-dev
Copy after login

Introduce middleware

In build/dev-server. Add middleware require at the end of the header require area in the js file.

  var bodyParser = require('body-parser');  var cookieParser = require('cookie-parser');
Copy after login

Then add the middleware call immediately after var app = express().

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
Copy after login

The two-line calling method of bodyParser is to set the content-type to 'application/json' and 'application/x-www-form-urlencoded' respectively.

After the addition is completed, it is easy to use.

End

The above is the detailed content of Share an example tutorial on building a vue-cli project.. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Discuz background login problem solution revealed Discuz background login problem solution revealed Mar 03, 2024 am 08:57 AM

The solution to the Discuz background login problem is revealed. Specific code examples are needed. With the rapid development of the Internet, website construction has become more and more common, and Discuz, as a commonly used forum website building system, has been favored by many webmasters. However, precisely because of its powerful functions, sometimes we encounter some problems when using Discuz, such as background login problems. Today, we will reveal the solution to the Discuz background login problem and provide specific code examples. We hope to help those in need.

Use JUnit unit testing framework Mock static method Use JUnit unit testing framework Mock static method Apr 18, 2024 pm 12:45 PM

How to Mock static methods using JUnit unit testing framework: PowerMock: Add PowerMock dependency. Use the @PrepareForTest annotation to specify the static method to be mocked. Use EasyMock to Mock static methods. EasyMock: Import the EasyMock class. Use the EasyMock.mockStatic() method to Mock static methods. Use the expect() method to set the expected value and the replay() method to perform the call.

Are you worried about WordPress backend garbled code? Try these solutions Are you worried about WordPress backend garbled code? Try these solutions Mar 05, 2024 pm 09:27 PM

Are you worried about WordPress backend garbled code? Try these solutions, specific code examples are required. With the widespread application of WordPress in website construction, many users may encounter the problem of garbled code in the WordPress backend. This kind of problem will cause the background management interface to display garbled characters, causing great trouble to users. This article will introduce some common solutions to help users solve the trouble of garbled characters in the WordPress backend. Modify the wp-config.php file and open wp-config.

Internet Explorer opens Edge: How to stop MS Edge redirection Internet Explorer opens Edge: How to stop MS Edge redirection Apr 14, 2023 pm 06:13 PM

It's no secret that Internet Explorer has fallen out of favor for a long time, but with the arrival of Windows 11, reality sets in. Rather than sometimes replacing IE in the future, Edge is now the default browser in Microsoft's latest operating system. For now, you can still enable Internet Explorer in Windows 11. However, IE11 (the latest version) already has an official retirement date, which is June 15, 2022, and the clock is ticking. With this in mind, you may have noticed that Internet Explorer sometimes opens Edge, and you may not like it. So why is this happening? exist

How to quickly build a statistical chart system under the Vue framework How to quickly build a statistical chart system under the Vue framework Aug 21, 2023 pm 05:48 PM

How to quickly build a statistical chart system under the Vue framework. In modern web applications, statistical charts are an essential component. As a popular front-end framework, Vue.js provides many convenient tools and components that can help us quickly build a statistical chart system. This article will introduce how to use the Vue framework and some plug-ins to build a simple statistical chart system. First, we need to prepare a Vue.js development environment, including installing Vue scaffolding and some related plug-ins. Execute the following command in the command line

What should I do if win11 cannot use ie11 browser? (win11 cannot use IE browser) What should I do if win11 cannot use ie11 browser? (win11 cannot use IE browser) Feb 10, 2024 am 10:30 AM

More and more users are starting to upgrade the win11 system. Since each user has different usage habits, many users are still using the ie11 browser. So what should I do if the win11 system cannot use the ie browser? Does windows11 still support ie11? Let’s take a look at the solution. Solution to the problem that win11 cannot use the ie11 browser 1. First, right-click the start menu and select "Command Prompt (Administrator)" to open it. 2. After opening, directly enter "Netshwinsockreset" and press Enter to confirm. 3. After confirmation, enter "netshadvfirewallreset&rdqu

How to use mock to simulate data problems in vite+vue3 How to use mock to simulate data problems in vite+vue3 May 15, 2023 am 08:07 AM

1. Install mockjs and vite-plugin-mocknpmimockjsvite-plugin-mock--save-dev2. Configure the usage of vite-plugin-mock in the vite.config.ts file import{defineConfig}from'vite'importvuefrom'@vitejs/plugin -vue'import{viteMockServe}from'vite-plugin-mock

Can buildings be built in the wild in Mistlock Kingdom? Can buildings be built in the wild in Mistlock Kingdom? Mar 07, 2024 pm 08:28 PM

Players can collect different materials to build buildings when playing in the Mistlock Kingdom. Many players want to know whether to build buildings in the wild. Buildings cannot be built in the wild in the Mistlock Kingdom. They must be within the scope of the altar. . Can buildings be built in the wild in Mistlock Kingdom? Answer: No. 1. Buildings cannot be built in the wild areas of the Mist Lock Kingdom. 2. The building must be built within the scope of the altar. 3. Players can place the Spirit Fire Altar by themselves, but once they leave the range, they will not be able to construct buildings. 4. We can also directly dig a hole in the mountain as our home, so we don’t need to consume building materials. 5. There is a comfort mechanism in the buildings built by players themselves, that is to say, the better the interior, the higher the comfort. 6. High comfort will bring attribute bonuses to players, such as

See all articles