1.安装配置
cnpm install http-proxy-middleware -S
2.在src目录下创建setupProxy.js文件
setupProxy.js文件代码:
const { createProxyMiddleware } = require('http-proxy-middleware')
// https://blogs.zdldove.top/Home/Apis/listWithPage
module.exports = function (app) {
app.use(
createProxyMiddleware('/api', {
target: 'https://blogs.zdldove.top',
changeOrigin: true,
pathRewrite: {
'^/api': ''
}
}),
)
}
3.进行请求数据的时候将协议和域名替换为配置好的名字
axios.post('/api/Home/Apis/listWithPage').then(res => {
console.log(res)
})