• vue-cli开发环境前端跨域


    config/index.js

    proxyTable: {
          '/api1': {
            target: '******', changeOrigin: true, pathRewrite: {
              '^/api1': ''
            }
          }, '/api2': {
            target: '******', changeOrigin: true, pathRewrite: {
              '^/api2': ''
            }
          }, secure: false
        },

    ******  指你的请求接口

    config/dev.js   测试环境搭建

    'use strict'
    const merge = require('webpack-merge');
    const prodEnv = require('./prod.env');
    
    module.exports = merge(prodEnv, {
      NODE_ENV: '"development"',
      API_HOST: ['"/api1"', '"/api2"']
    });

    config/prod.js   生产环境

    'use strict';
    module.exports = {
      NODE_ENV: '"production"', API_HOST: ['"/api1"', '"/api2"']
    }

    axios 设置 withcredentials:true

    使用

    this.$axios.get(process.env.API_HOST[3] + '/util/captcha', {responseType: 'arraybuffer'}).then(res => {
              if (res.status === 200) {
                this.captchaSrc = 'data:image/png;base64,' + btoa(new Uint8Array(res.data).reduce((data, byte) => data + String.fromCharCode(byte), ''))
              } else {
                this.$message(res.data.msg)
              }
            });

    生产环境是需要后台做nginx反向代理(我们公司是这样的),然后又遇到本地环境session老是改变的问题,有人说是因为本地localhost和请求不再同一个域名下,withcredentials无效了。线上前端页面和后台接口在同一个域名下就没这个问题了。

    记录别的解决方案:

    https://blog.csdn.net/sky786905664/article/details/73920815

  • 相关阅读:
    Record
    Solution -「洛谷 P6287」「COCI 2016-2017」Mag
    Solution -「洛谷 P3773」「CTSC 2017」吉夫特
    Solution -「SP 106」BINSTIRL
    Record
    Record
    Record
    Solution Set -「CSP-S 2020」
    MDK在SRAM中运行-STM32F103RCT6为例
    STM8S103F3P STVD+COSMIC开发环境搭建
  • 原文地址:https://www.cnblogs.com/Merrys/p/9699549.html
Copyright © 2020-2023  润新知