vue2.96和3.X如何配置转发!

vue 2.96配置

打开config/index.js,找到

assetsPublicPath: '/',
proxyTable: {}

改成

assetsPublicPath: '/',
proxyTable: {
'/plus': {
target: 'https://www.xhcss.com',
changeOrigin: true,
pathRewrite: {
'^/plus': '/plus'
}
},
'/ws/*': {
target: 'ws://127.0.0.1:8082',
ws: true
}
},

只有一个就可以把wx那个删掉!

然后调用的时候

this.axios
.get('/plus/type_ajax.php', {
params: {
type: 'topmenu',
typeid: 0,
field: 'typename,id,icon'
}
})
.then(response => {
this.nbav = response.data.data
})

值得注意的是/plus前面不要加内容,不然不生效


vue3.x配置

在根目录新建

vue.config.js文件

module.exports = {
devServer: {
open: true,
host: 'localhost',
port: 8080,
https: false,
//以上的ip和端口是我们本机的;下面为需要跨域的
proxy: {//配置跨域
'/api': {
target: 'https://www.xhcss.com/',//这里后台的地址模拟的;应该填写你们真实的后台接口
ws: true,
changOrigin: true,//允许跨域
pathRewrite: {
'^/api': '' //请求的时候使用这个api就可以
}
}
}
}
}

然后调用的时候一样!

相关内容

发表评论

验证码:
点击我更换图片

最新评论