vue解决跨域问题

vue.config.js中

module.exports = {
                lintOnSave: false, //关闭代码校验
                devServer: {
                    open: true, // 是否自动弹出浏览器
                    port: 8000, // 修改默认端口
                    proxy: { // 代理转发(服务器与服务器之间是不存在跨域的)
                        "/api": {
                            // 1 目标路径
                            //重写路径为api
                         target: "https://xxx.cn/api/",
                            //2 允许跨域
                            changOrigin: true,
                            //3 重写路径
                            pathRewrite: { // 这里理解成用‘/api’代替target里面的地址
                                '^/api': ''
                            },
                            secure: false, // 如果是https接口,需要配置这个参数
                            ws: true, // 是否开启websockes协议请求
                        }
                    },
                }
            }

使用时

this.$axios({
        method: "get",
        url: `/api/xx/checkById`,
        params: {
          id,
        },
      }).then((response) => {
        console.log(response.data);
      });
本文来自投稿,不代表本站立场,如若转载,请注明出处:https://blog.itliujia.cn/info/20220498.html
HbuilderX去除格式代码时候多余空白行
« 上一篇 04-26
vue.config.js
下一篇 » 05-10