Vue開發環境跨域訪問其他服務器或者本機其他埠,需要配置專案中config/index.js檔案,修改如下
module.exports = {
dev: {
// Paths
assetsSubDirectory: 'static',
assetsPublicPath: '/',
proxyTable: {
'/api':{
target:'http://192.168.1.99:8080/',
changeOrigin:true,
pathRewrite:{
'^/api':''
}
}
},
其中主要是加入
proxyTable: {
'/api':{
target:'http://192.168.1.99:8080/',
changeOrigin:true,
pathRewrite:{
'^/api':''
}
}
}
這樣你通過axios 或fetche訪問 /api/** 便相當于跨域訪問了 http://192.168.1.99:8080/
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/153822.html
標籤:JavaScript
