Home >Web Front-end >JS Tutorial >How to operate Vue to make a proxy
This time I will show you how to operate Vue to make a proxy agent. What are the precautions for operating Vue to make a proxy agent? The following is a practical case, let's take a look.
When developing the Vue framework, you will encounter cross-domain problems. You can configure the proxyTable content in config/index.js and use the proxy proxy.
// config/index.js 文件
proxyTable: {
'/api': {
target: 'http://192.168.149.90:8080/', // 设置你调用的接口域名和端口号
changeOrigin: true, // 跨域
pathRewrite: {
'^/api': '/'
}
}
},
This is understood as using '/api' to replace the address in the target. In the later components, when we drop the interface, we directly use api to replace it. For example, I want to call 'http://192.168.149.90:8080/xxx/duty ?time=2017-07-07 14:57:22', directly write '/api/xxx/duty?time=2017-07-07 14:57:22'
in dev.env Configure the development environment request address in .js
// config/dev.env.js 文件
module.exports = merge(prodEnv, {
NODE_ENV: '"development"',
ADMIN_SERVER: '"/api/"',
});
If you request axios for the plug-in, configure it as follows
const adminServer = axios.create({
baseURL: process.env.ADMIN_SERVER,
});
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to the php Chinese website Other related articles!
Recommended reading:
How to use webpack modular management and packaging tool
security.js RSA to create encryption function
The above is the detailed content of How to operate Vue to make a proxy. For more information, please follow other related articles on the PHP Chinese website!