在webpack.dev.config中配置了
devServer: {
contentBase: path.join(__dirname, './dist'),
historyApiFallback: true,
host: '0.0.0.0',
proxy: {
'/api/weixin/*': {
target: 'https://api.mch.weixin.qq.com',
secure: false, // 接受 运行在 https 上的服务
changeOrigin: true
}
}
}
在action中使用
axios({
method:"POST",
url:"/api/weixin/pay/unifiedorder",
data:{
"appid":"wx2421b1c4370ec43b",
"mch_id":"10000100",
"nonce_str":"6cefdb308e1e2e8aabd48cf79e546a02",
"out_refund_no":"1415701182",
"ut_trade_no":"1415757673",
"refund_fee":"1",
"total_fee":"1",
"transaction_id":"",
"sign":"FE56DD4AA85C0EECA82C35595A69E153"
},
withCredentials:true
}).then(function(res){
console.log(res);
dispatch(getUserInfoSuccess(res.data));
}).catch(function(error){
dispatch(getUserInfoFail());
console.log(error);
});
运行后会报错404
POST http://localhost:8080/api/weixin/pay/unifiedorder 404 (Not Found)