下載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")