解决uniapp跨域
建一个vue.config.js,然后调用的话前面要加/api/,比如后端接口名字是/user/login,那就是/api/user/login,用自己封装好的方法调用就好了
module.exports = {
// publicPath:'',
// outputDir: 'dist', //build输出目录
// assetsDir: 'assets', //静态资源目录(js, css, img)
// lintOnSave: false, //是否开启eslint
devServer: {
open: false, //是否自动弹出浏览器页面
host: "127.0.0.1",
port: '8084',
https: false, //是否使用https协议
hotOnly: true,
proxy: {
// 配置跨域
'/api': {
// target: "http://。。。。", // 域名
// target: "http://。。。。",// 域名
target: "http://。。。。",// 域名
ws: true,
changOrigin: true,
pathRewrite: {
'^/api': '/api'
},
logLevel: 'debug',
},
}
}
}