vue 实现cli3.0中使用proxy进行代理转发
时间:2023-03-10 10:45:41|栏目:vue|点击: 次
解决方法:
在vue项目的根目录下添加 vue.config.js文件,文件中需要按照下面写法来写
module.exports = {
lintOnSave: true,
devServer: {
proxy: {
// proxy all requests starting with /api to jsonplaceholder
'/api': {
target: 'http://localhost:8080', //代理接口
changeOrigin: true,
pathRewrite: {
'^/api': '/mock' //代理的路径
}
}
}
}
}
然后你就可以在代码中使用 /api 来代替http://localhost:8080/mock啦
上一篇:Vue echart实现柱状图,电池图,3D柱图和3D圆柱图代码详解
栏 目:vue
本文标题:vue 实现cli3.0中使用proxy进行代理转发
本文地址:http://www.codeinn.net/misctech/227177.html






