VUE跨域设置

根目录config文件夹:
在这里插入图片描述

proxyTable 是 webpack-dev-server 的功能,应该把相关配置放到 Webpack 配置里。

proxyTable: {
      '/api': {
        target: 'http://127.0.0.1:8011/',  //这里后台的地址模拟的;应该填写你们真实的后台接口
        changOrigin: true,  //允许跨域
        pathRewrite: {
          /* 重写路径,当我们在浏览器中看到请求的地址为:http://localhost:8080/api/core/getData/userInfo 时
            实际上访问的地址是:http://121.121.67.254:8185/core/getData/userInfo,因为重写了 /api
           */
          '^/api': ''
        }
      },
    },

dev里面:
在这里插入图片描述
proxyTable只用写api那条就行了

访问地址:api/accounts/login/

POST:

this.$http.post("api/accounts/login/", {name: this.form.name, password: this.form.password }, {emulateJSON: true}).then((response) => {
          console.log(response.body);
          this.user = response.body.user;
          for (var i = 0; i < this.user.length; i++) {
            if (this.user[i].name === this.form.name && this.user[i].password === this.form.password) {
              this.form.type = this.user[i].type;
              this.setUserInfo(this.form);
              this.$router.push({path: 'home'});
              return;
            }
          }
          this.tips = '密码不正确!';
          this.$message({
            message: this.tips,
            type: 'warning'
          });
        }, response => {
          this.$message({
            message: '数据请求失败',
            type: 'error'
          });
        });

修改完后要重启 npm run server 才能生效

在这里插入图片描述
可以看到/app被正则替换为空字符,实际访问的接口是http://127.0.0.1:8000/accounts/login/

Django跨域设置:
注释掉setting.py的MIDDLEWARE的’django.middleware.csrf.CsrfViewMiddleware’

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

nickdlk

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值