下载axios
npm install axios --save
引用axios
在需要axios请求的组件进行引用
import axios from ‘axios’
修改node配置
proxyTable: {
"需要进行跨域访问时访问的域名":{
target:"目标域名",
changeOrigin:true,
pathRewrite:{
"^/需要进行跨域访问时访问的域名":""
}
}
},
示例
proxyTable: {
"/api":{
target:"https://www.baidu.cn/",
changeOrigin:true,
pathRewrite:{
"^/api":""
}
}
},
进行跨域访问
axios.get("api/Shop/subjectList")