react的状态点击事件的问题
最近在使用react解决点击事件的时候发现使用state用setstate效果是好的,换成mobx后失效
下面上代码:
import React, {Component} from 'react'
import {Card, Button} from 'antd'
import {BarList} from "./inventoryStore";
import * as styles from './style.pcss';
import {InventoryTable} from "./inventoryTable";
class BarExtra extends Component<any, any> {
constructor(props) {
super(props)
this.state = {
barTitle: '列表数据'
}
}
onClick = item => e => {
// inventoryStore.changeBarTitle(item)
this.setState({
barTitle: item
})
}
render() {
const _style = {
color: '#1890ff'
};
return (
<>
{
BarList.map((item, index) => {
return<a key={index}
className={styles.bar}
onClick={this.onClick(item)}
style={item === this.state.barTitle? _style : {} }
>
<span>{item}</span>
</a>
})
}
</>
)
}
}
如图这样写是好的但是换成mobx中
@action changeBarTitle(item) {
this.barTitle = item
}
这么写就失效了
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
action是要写在 store 中的,然后在需要用到 store 的组件中,先引入
然后调用