Today I encountered a small problem during development. How to solve the cross-domain problem when debugging the vue+Java backend. The editor below will share the solution with you. Friends who are interested can take a look.
Today I encountered a problem during the development process and got a set of vue code. I plan to adjust some styles of this code. The Java back-end code has been written and deployed online. At this time, when running the vue project on the command line, access will be restricted, data cannot be retrieved, and cross-domain access fails. What can be done at this time?
First of all, we need to understand what cross-domain access is?
Cross-domain means that the browser cannot execute scripts from other websites. It is caused by the browser's same-origin policy, which is a security restriction imposed by the browser on JavaScript.
The so-called same origin means that the domain name, protocol and port are the same. For example:
http://www.123.com/index.html call http://www.123.com/server.php (non-cross-domain)
http://www.123.com/index.html calls http://www.456.com /server.php (different primary domain names: 123/456, cross-domain)
http://abc.123.com/index.html Call http://def.123.com/server .php (different subdomain names: abc/def, cross-domain)
http://www.123.com:8080/index.html Call http://www.123.com:8081 /server.php (different ports: 8080/8081, cross-domain)
http://www.123.com/index.html Call https://www.123.com/server. php (different protocols: http/https, cross-domain)
Please note: Although localhost and 127.0.0.1 both point to this machine, they are also cross-domain.
After knowing the concept of cross-domain, how do we solve it?
My situation here is like this. The backend is on the server, but vue runs locally. There are many cross-domain proxy tools on the Internet, but they are all troublesome. Because the vue-cli scaffolding tool has already taken care of it for us, we can easily solve cross-domain problems with just a little configuration.
We open the config/index.js file and find the following code:
Configure proxy in proxyTable: {}, configuration information As follows:
proxyTable: { '/project_dzff/': { target: 'http://120.92.45.71/', //域名 secure: false, changeOrigin: false, } },
After the agent is configured, modify the project’s calling interface address information so that it can call what we configured.
serverRoot: env === 'development' ? '/project_dzff' : env === 'production' ? '/project_dzff' : 'https://debug.url.com'
The original access to http://120.92.45.71/ has been adjusted to access project_deff, which is the name we defined ourselves.
At this time we run the vue project, as shown in the figure:
At this time, basically the access has been successfully proxied to the local, and then you can Use the local vue project to access server-side data!
Summarize
The above is the detailed content of Solve the cross-domain problem when debugging vue+Java backend. For more information, please follow other related articles on the PHP Chinese website!

JVM handles operating system API differences through JavaNativeInterface (JNI) and Java standard library: 1. JNI allows Java code to call local code and directly interact with the operating system API. 2. The Java standard library provides a unified API, which is internally mapped to different operating system APIs to ensure that the code runs across platforms.

modularitydoesnotdirectlyaffectJava'splatformindependence.Java'splatformindependenceismaintainedbytheJVM,butmodularityinfluencesapplicationstructureandmanagement,indirectlyimpactingplatformindependence.1)Deploymentanddistributionbecomemoreefficientwi

BytecodeinJavaistheintermediaterepresentationthatenablesplatformindependence.1)Javacodeiscompiledintobytecodestoredin.classfiles.2)TheJVMinterpretsorcompilesthisbytecodeintomachinecodeatruntime,allowingthesamebytecodetorunonanydevicewithaJVM,thusfulf

JavaachievesplatformindependencethroughtheJavaVirtualMachine(JVM),whichexecutesbytecodeonanydevicewithaJVM.1)Javacodeiscompiledintobytecode.2)TheJVMinterpretsandexecutesthisbytecodeintomachine-specificinstructions,allowingthesamecodetorunondifferentp

Platform independence in JavaGUI development faces challenges, but can be dealt with by using Swing, JavaFX, unifying appearance, performance optimization, third-party libraries and cross-platform testing. JavaGUI development relies on AWT and Swing, which aims to provide cross-platform consistency, but the actual effect varies from operating system to operating system. Solutions include: 1) using Swing and JavaFX as GUI toolkits; 2) Unify the appearance through UIManager.setLookAndFeel(); 3) Optimize performance to suit different platforms; 4) using third-party libraries such as ApachePivot or SWT; 5) conduct cross-platform testing to ensure consistency.

Javadevelopmentisnotentirelyplatform-independentduetoseveralfactors.1)JVMvariationsaffectperformanceandbehavioracrossdifferentOS.2)NativelibrariesviaJNIintroduceplatform-specificissues.3)Filepathsandsystempropertiesdifferbetweenplatforms.4)GUIapplica

Java code will have performance differences when running on different platforms. 1) The implementation and optimization strategies of JVM are different, such as OracleJDK and OpenJDK. 2) The characteristics of the operating system, such as memory management and thread scheduling, will also affect performance. 3) Performance can be improved by selecting the appropriate JVM, adjusting JVM parameters and code optimization.

Java'splatformindependencehaslimitationsincludingperformanceoverhead,versioncompatibilityissues,challengeswithnativelibraryintegration,platform-specificfeatures,andJVMinstallation/maintenance.Thesefactorscomplicatethe"writeonce,runanywhere"


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

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

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

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.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function
