前端跨域相关

注:前端配置跨域后服务器端(Nginx)也需要配置,否则接口无法访问

vue跨域

配置文件 /vue.config.js

devServer: {

port: 7100,

proxy: {

'/api': {

target: 'http://域名',

changeOrigin: true,

logLevel: 'debug',

pathRewrite: { '^/api': '' }

}

}

}

调用

import axios from 'axios'

const headers = {

'Content-Type': 'application/json;charset=utf-8'

}

axios.post('/bryant/接口地址', headers).then((res) => {

cosole.log(res)

})

uniapp跨域

配置文件 /manifest.json

"devServer" : {

"https" : false,

"port" : 7101,

"proxy": {

"/api": {

"target": "https://域名",

"changeOrigin": true,

"secure": false,

"pathRewrite":{"^/api":""}

}

}

},

调用

uni.request({

url: '/api/接口',

method: 'POST',

success:ret=>{

console.log(ret)

}

})

相关推荐
2301_7978928316 小时前
论文阅读:《Hypergraph Motif Representation Learning》
论文阅读·1024程序员节
CoderYanger1 天前
前端基础——CSS练习项目:百度热榜实现
开发语言·前端·css·百度·html·1024程序员节
liu****1 天前
13.POSIX信号量
linux·开发语言·c++·算法·1024程序员节
liu****2 天前
12.线程同步与互斥
linux·数据结构·c++·算法·1024程序员节
CoderJia程序员甲2 天前
GitHub 热榜项目 - 日榜(2025-11-08)
ai·开源·github·1024程序员节·ai教程
大布布将军2 天前
《前端九阴真经》
前端·javascript·经验分享·程序人生·前端框架·1024程序员节
liu****2 天前
12.线程同步和生产消费模型
linux·服务器·开发语言·c++·1024程序员节
小苏兮2 天前
【把Linux“聊”明白】自动化构建-make/Makefile详解
linux·服务器·学习·自动化·1024程序员节
新知图书3 天前
RDD的特点、算子与创建方法
数据分析·spark·1024程序员节
AORO20253 天前
智能三防手机哪款好?22000mAh+夜视+露营灯打造专业户外装备
服务器·网络·智能手机·电脑·1024程序员节