1.config/index.js 修改 proxyTable
proxyTable: {
'/api': {
target: 'http://shuige.wicp.vip/', //目標介面域名
changeOrigin: true, //是否跨域
pathRewrite: {
'^/api': '/' //重寫介面 后臺介面指向不統一 所以指向所有/
}
},
cssSourceMap: false
},
2. 請求得時候 介面地址加上前綴
import axios from 'axios' export default { created() { // 1. 代理成功 // http://shuige.wicp.vip/users/proxy 轉換成 http://localhost:8080/api/users/proxy axios.get('/api/users/proxy').then(res => { // /api 不能少 console.log(res) }) } }
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/131643.html
標籤:JavaScript
