vue 解决不能携带session问题

    xiaoxiao2022-07-05  174

    1 需要配置代理

    devServer: { host: '127.0.0.1', port: 8010, proxy: { '/api/': { target: 'http://127.0.0.1:8080', changeOrigin: true, pathRewrite:{ '/api':'/xxxxxx' } } }

    2 修改配置文件 默认为false不允许携带session,改为true

    axios.defaults.withCredentials=true;

    3 修改axios中的请求即可

    this.$axios.post('/api/xx/xxx', {}, { headers: { "Content-Type": "application/json;charset=utf-8" } }).then(function(response) { // 这里是处理正确的回调 }).catch(function(response) { // 这里是处理错误的回调 console.log(response) });

     

    最新回复(0)