vue-配置跨域

tech2022-08-15  140

// vue.config.js module.exports = { devServer:{ proxy: { '/life-medical-medical': { // 匹配以此开头的请求 changeOrigin: true, // 如果接口跨域,需要进行这个参数配置 target: 'http://10.1.28.216:8090', // 接口的域名 }, '/hello': { changeOrigin: true, target: 'http://10.1.36.248:3333', } } } }

vue.config.js 改动后必须重启项目!!!

export default { name: 'App', created() { request({ method: 'post', // 实际请求路径为:http://10.1.28.216:8090/life-medical-medical/V1.0.0/web/... url: '/life-medical-medical/V1.0.0/web/article/assortment/getAssortments?token=c4a325fc75dd42f5990776de', }).then(value => { console.log(value) }).catch(reason => { console.log(reason) }) request({ // 实际请求路径为:http://10.1.36.248:3333/hello/home url: '/hello/home', }).then(value => { console.log(value) }).catch(reason => { console.log(reason) }) } }

更多用法参考:https://blog.csdn.net/m0_37631322/article/details/92841290

最新回复(0)