Sin*_*met 87 reactjs react-native redux axios
我正在尝试将GET请求作为第二个参数发送,但它在作为url时不起作用.
这有效,$ _GET ['naam']返回测试:
export function saveScore(naam, score) {
return function (dispatch) {
axios.get('http://****.nl/****/gebruikerOpslaan.php?naam=test')
.then((response) => {
dispatch({type: "SAVE_SCORE_SUCCESS", payload: response.data})
})
.catch((err) => {
dispatch({type: "SAVE_SCORE_FAILURE", payload: err})
})
}
};
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试这个时,根本没有任何东西$_GET:
export function saveScore(naam, score) {
return function (dispatch) {
axios.get('http://****.nl/****/gebruikerOpslaan.php',
{
password: 'pass',
naam: naam,
score: score
})
.then((response) => {
dispatch({type: "SAVE_SCORE_SUCCESS", payload: response.data})
})
.catch((err) => {
dispatch({type: "SAVE_SCORE_FAILURE", payload: err})
})
}
};
Run Code Online (Sandbox Code Playgroud)
为什么我不能这样做?在文档中,它清楚地表明它是可能的.有了$_POST它也不行.
Nic*_*sev 225
axios.get 接受请求配置作为第二个参数(不是查询字符串参数).
您可以使用paramsconfig选项设置查询字符串参数,如下所示:
axios.get('/api', {
params: {
foo: 'bar'
}
});
Run Code Online (Sandbox Code Playgroud)
dan*_*ren 55
在客户端:
axios.get('/api', {
params: {
foo: 'bar'
}
});
Run Code Online (Sandbox Code Playgroud)
在服务器上:
function get(req, res, next) {
let param = req.query.foo
.....
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
107670 次 |
| 最近记录: |