gpt4 book ai didi

mobx - 元素描述符的 .kind 属性必须是 "method"或 "field"

转载 作者:行者123 更新时间:2023-12-05 08:26:39 27 4
gpt4 key购买 nike

我正在关注 mobx-react-router 的文档但是在尝试运行我的应用程序时,我在浏览器中收到以下错误:

Uncaught TypeError: An element descriptor's .kind property must be either "method" or "field", but a decorator created an element descriptor with .kind "undefined"
at _toElementDescriptor (app.js:49988)
at _toElementFinisherExtras (app.js:49990)
at _decorateElement (app.js:49980)
at app.js:49976
at Array.forEach (<anonymous>)
at _decorateClass (app.js:49976)
at _decorate (app.js:49958)
at Module../src/App/UserStore.js (app.js:50012)
at __webpack_require__ (bootstrap:19)
at Module../src/index.js (index.js:1)

这是我初始化的方式:

const appContainer = document.getElementById('app');
if(appContainer) {
const browserHistory = createBrowserHistory()
const routingStore = new RouterStore();

const stores = {
users: userStore,
routing: routingStore
}

const history = syncHistoryWithStore(browserHistory, routingStore);

ReactDOM.render(
(
<Provider {...stores}>
<Router history={history}>
< App />
</Router>
</Provider>
),
appContainer);
}

这就是我的使用方式:

@inject('routing')
@inject('users')
@observer
class App extends Component { ...

我的 UserStore:

import { observable, action, computed } from "mobx"

class UserStore {
@observable users = [];

@action addUser = (user) => {
this.users.push(user)
}

@computed get userCount () {
return this.users.length
}
}

const store = new UserStore();
export default store;

我已尝试用 Google 搜索此错误,但没有返回任何有用的结果。知道我做错了什么吗?

最佳答案

如果你使用 Babel 7 安装装饰器支持:

npm i -D\
@babel/plugin-proposal-class-properties\
@babel/plugin-proposal-decorators

然后在你的 .babelrcwebpack.config.js 文件中启用它:

{
"plugins": [
["@babel/plugin-proposal-decorators", { "legacy": true}],
["@babel/plugin-proposal-class-properties", { "loose": true}]
]
}

请注意,遗留模式很重要(将装饰器提案放在首位也很重要)。非遗留模式是 WIP .

引用:https://mobx.js.org/best/decorators.html

关于mobx - 元素描述符的 .kind 属性必须是 "method"或 "field",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52628207/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com