Vue3解决跨域问题,报错Access-Control-Allow-Origin

解决方案:
1、在项目的config.js文件添加以下配置
在这里插入图片描述

    proxy: {
            '/api': {                              //需要代理的接口
                target: 'http://localhost:8081',//springboot的端口号
                changeOrigin: true,             //是否跨域
                ws: true,                       //是否代理 websockets
                secure: true,                   //是否https接口
                pathRewrite: {                  //路径重置
                    '^/api': ''
                }

            },
        },
    },

2.在vue文件编写请求

  created(){
    axios.get('api/user/findUserAll').then(function (resp) {
		console.log(resp)
    })

  },


版权声明:本文为weixin_45425813原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。