我使用了以下依赖项:
"dependencies": {
"axios": "^0.19.0",
"i18next": "^19.9.2",
"i18next-browser-languagedetector": "^6.0.1",
"node-sass": "^4.14.1",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-i18next": "^11.8.9",
"react-redux": "^7.0.3",
"react-router-dom": "^5.2.0",
"react-scripts": "3.0.1",
"redux": "^4.0.1",
"redux-thunk": "^2.3.0"
},问题
我正在尝试将我的所有redux操作导出为:
export * as actions from './actions';我得到了以下错误:
./src/app/redux/index.js 4:9
Module parse failed: Unexpected token (4:9)
You may need an appropriate loader to handle this file type.
> export * as actions from './actions';我正在从react-17迁移我的代码(在那里它工作得很好)。
发布于 2021-03-10 19:15:45
我不相信有这样的语法可以让你在JavaScript中使用export * as obj。为了定义您的操作,您必须对每个操作执行以下操作:
actions.js
export const myAction = () => {
// Do stuff
};
export const myAction2 = () => {
// Do stuff
};Component.js
import * as actions from "../directory/to/actions";如果您在一个文件中有许多操作,并希望将它们保留在那里。您可以将它们存储为对象并将其导出为默认值,如果您希望这样做的话。
actions.js
const actions = {
myAction: () => {
// Do stuff
},
myAction2: () => {
// Do stuff
}
}
export default actions;Component.js
import actions from "../directory/to/actions";https://stackoverflow.com/questions/66560279
复制相似问题