你的位置:首页 > 信息动态 > 新闻中心
信息动态
联系我们

vue解决跨域问题

2021/12/14 16:18:44

添加配置文件

vue.config.js 文件
与src同级
在这里插入图片描述

文件内容

const path = require('path')

// vue.config.js
const vueConfig = {
  devServer: {
    // development server port 8000
    //本机启动的端口号
    port: 8080,
    proxy: {
      '/apis': {
      // 请求的域名地址
        target: 'https://crm-stg.cosstores.cn/cosminiprogram', // http://192.168.1.151:80 process.env.VUE_APP_APIURL
        pathRewrite: { '^/apis': '' }, //路径重写
        ws: false,
        changeOrigin: true  //是否开启跨域
      }
    }
  },

  
}

module.exports = vueConfig

发起请求

/apis是配置文件定义的

axios.post('/apis/question/previewQuestion', {
        questionnaireId: "99410997320827635",
        sessionId:"006FA8F20EE94D37A56766190B978271"
    }).then(response => {
        console.log('/a1', response.data)
    }, error => {
        console.log('错误', error.message)
    })

重启