Detailed explanation of Vue data proxy

Detailed explanation of Vue data proxy

There are many ways to solve cross-domain problems, such as jsonp and cors, but both require the help of backend personnel.

1. What I am going to talk about below is a solution that front-end personnel can complete in vue-cli - data proxy

(1) First, you need to download a plug-in from the configuration item of the vue-cli official document

insert image description here

(2) Paste the part in the red circle in the above picture into the babel.config.js of the vue scaffold

insert image description here

(3) The red circled part http://localhost:5000 in the above figure is the local server address, but the service started by my project is http://localhost:8082/

At this point I send a request to the backend in my project

insert image description here

You can get the data

insert image description here

Note that if there is a file with the same name as the local server in the punlic folder of your project, it will be read first in the public folder of the project.

2. The above data agent still has the following defects

(1) If there is a local public file with the same file name as the server file, the local file will be returned first.

(2) Only a single agent can be created

1. In order to solve the above problems, another way to create a proxy can be used

insert image description here

In the above figure, /api and /apii are two different data agents.

2. At the same time, the interface path for the front-end to send requests should also be changed from http://localhost:8082/students to the following, so that files in the local public folder will not be requested.

insert image description here

Summarize

This article ends here. I hope it can be helpful to you. I also hope you can pay more attention to more content on 123WORDPRESS.COM!

You may also be interested in:
  • Detailed explanation of VUE's data proxy and events
  • Vue2.x obtains data from QQ music API through the backend interface proxy
  • Detailed explanation of proxy access to data in Vue source code

<<:  A detailed introduction to wget command in Linux

>>:  Examples of implementing progress bars and order progress bars using CSS

Recommend

JS implements the dragging and placeholder functions of elements

This blog post is about a difficulty encountered ...

Detailed explanation of how Angular handles unexpected exception errors

Written in front No matter how well the code is w...

How to insert a link in html

Each web page has an address, identified by a URL...

Analyzing the MySql CURRENT_TIMESTAMP function by example

When creating a time field DEFAULT CURRENT_TIMEST...

How to install and configure ftp server in CentOS8.0

After the release of CentOS8.0-1905, we tried to ...

Detailed explanation of the execution order of JavaScript Alert function

Table of contents question analyze solve Replace ...

The hottest trends in web design UI in 2013 The most popular UI designs

Time flies, and in just six days, 2013 will becom...

JS implements random roll call system

Use JS to implement a random roll call system for...

Introduction to the use of CSS3 filter attribute

1. Introduction When writing animation effects fo...

An article to master MySQL index query optimization skills

Preface This article summarizes some common MySQL...

Test and solution for MySQL's large memory usage and high CPU usage

After the changes: innodb_buffer_pool_size=576M -...

Analysis of the advantages of path.join() in Node.js

You might be wondering why you should use the pat...

MySQL single table query example detailed explanation

1. Prepare data The following operations will be ...

Nginx configuration to achieve multiple server load balancing

Nginx load balancing server: IP: 192.168.0.4 (Ngi...