一级标题
uniapp跨域 方法一
// 配置文件manifest.json
"h5": {
"router": {
"base": "./",
"mode": "hash"
}
//跨域
"devServer": {
"https": false,
"port": 8080,
"disableHostCheck": true
,
"proxy": {
//多个跨越更改 复制下面更改名字(api)
"/api": {
"target": "你要跨域的网址域名",
"changeOrigin": true, //是否跨域
"secure": false, // 设置支持https协议的代理
"pathRewrite": {
"^/api": ""
}
}
}
}
}
uniapp跨域 方法二 (vue框架也可用)
//vue.config.js
module.exports = {
// ...其他配置项
devServer: {
"https": false,
"port": 8080,
"disableHostCheck": true,
"proxy": {
"/api": {
"target": "你要跨域的网址域名",
"changeOrigin": true, //是否跨域
"secure": false, // 设置支持https协议的代理
"pathRewrite": {
"^/api": ""
}
}
}
},
}
uniapp使用
uni.request({
method:"POST",
url: '/api + 路径', // api自己设置的跨域名称
data:{},
})