记录下:
proxy: {
"/v1": {
target: "https://easy-mock.com/mock/5.........cae50/example",
changeOrigin: true, // 跨域
pathRewrite: {
"^/v1": "" // 实际请求路径不含v1字段
}
}
}
理解:首先发的请求以v1开头,来替换实际路径https://easy-mock.com/mock/5c...........ae50/example
this.$axios({
method: "get",
url: "v1/userList"
}).then(res=>{
})
最后变成,请求https://easy-mock.com/mock/5c.................ae50/example/userList
注意:v1/userList 中v1 不要省略,会404.