import{_ as s,o as a,c as n,R as p}from"./chunks/framework.6241eaf2.js";const A=JSON.parse('{"title":"配置 proxy 跨域","description":"","frontmatter":{},"headers":[],"relativePath":"guide/vue2/proxy.md","filePath":"guide/vue2/proxy.md","lastUpdated":1731315864000}'),l={name:"guide/vue2/proxy.md"},o=p(`

配置 proxy 跨域

如果你的项目需要跨域设置,你需要打来 vue.config.js proxy 注释 并且配置相应参数

!!!注意:你还需要将 src/config/env.development.js 里的 baseApi 设置成 '/'

javascript
module.exports = {
  devServer: {
    // ....
    proxy: {
      //配置跨域
      "/api": {
        target: "https://test.xxx.com", // 接口的域名
        // ws: true, // 是否启用websockets
        changOrigin: true, // 开启代理,在本地创建一个虚拟服务端
        pathRewrite: {
          "^/api": "/",
        },
      },
    },
  },
};

使用 例如: src/api/home.js

javascript
export function getUserInfo(params) {
  return request({
    url: "/api/userinfo",
    method: "post",
    data: qs.stringify(params),
  });
}
`,6),e=[o];function t(c,r,D,y,F,i){return a(),n("div",null,e)}const d=s(l,[["render",t]]);export{A as __pageData,d as default};