[英]How to use proxy in webpack and reactjs?
我在“ webpack.config.dev.js”中添加了以下代碼
devServer: {
proxy:{
target:"http://localhost:8081"
}
}
我正在使用以下axios代碼,但未將代理作為URL
axios({
method:"post",
url:"/add_order_product",
data:result
}).then(response =>{
alert(response.data);
if(response.data === true){
// console.log(response);
alert("saving data");
}
}).catch(response =>{
console.log(response);
});
默認情況下,webpack-dev-server不啟用根代理。 為了啟用根代理,需要將index
屬性設置為falsy值。 他們的文檔也設置了context
屬性,盡管他們沒有明確表示需要root代理。 請嘗試以下配置, 這是指向 webpack-dev-server代理文檔的鏈接。
devServer: {
index: '',
proxy: {
context: () => true,
target: "http://localhost:8081"
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.