我想在js中发送redux操作的参数,但API开发人员在API部分(2fa_code(中使用了数字名称值。现在我试图将参数发送到API,但给出了一个错误(标识符或关键字不能立即跟随数字文字(。请帮我怎么解决这个问题。
export const setTwofaGoogle = ({ 2fa_code }) => (dispatch) => {
const token = localStorage.getItem("token");
// Headers
const config = {
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
},
};
// Request body
const body = {
2fa_code
};
axios
.post(TWO_FA_CODE_CONFIRM_URL, body, config)
.then((res) =>
dispatch({
type: SET_2FA_METHOD_GOOGLE_SEUCCES,
payload: res.data,
})
)
.catch((err) => {
dispatch({
type: SET_2FA_METHOD_GOOGLE_FAIL,
payload: err.data,
});
console.log(err);
});
};
反应错误
Failed to compile
./src/redux/actions/settingActions.js
Line 47:14: Parsing error: Identifier 'setTwofaGoogle' has already been declared
45 | /* -------------------------- 2fa Code Confirm -------------------------- */
46 |
> 47 | export const setTwofaGoogle = ({ 2fa_code }) => (dispatch) => {
| ^
48 | const token = localStorage.getItem("token");
49 | // Headers
50 | const config = {
This error occurred during the build time and cannot be dismissed.
不确定这个错误与这个问题有什么关系,因为它没有说明任何关于数值变量名的信息。
无论如何,对于这样的变量,除了使用括号符号之外,您没有其他解决方案
export const setTwofaGoogle = data => dispatch => {
// ...
const body = {
'2fa_code': data['2fa_code']
}
// ...
}