这是一个页面组件;
import react from 'react'
import { connect } from 'dva'
// @connect(state => {
// const listName = state.ComponentsStore.listName;
// })
class Message extends react.Component {
componentDidMount() {
console.log(this.props.listName, 'componentDidMount');
}
componentDidUpdate(prevProps) {
// 组件数据发生变化时,进行对比
// this.props.listName是现在的数据,
// prevprops.listname 是之前的数据,
// 比较数据前后变化,不相等则触发内部函数
if (this.props.listName !== prevProps.listName) {
console.log(this.props.listName, 'componentDidUpdate')
}
}
componentWillUnmount() {
console.log(this.props.listName, 'componentWillUnmount')
}
setProp = () => {
// 点击的时候通过this.props.dispatch 驱动namespace里中叫ComponentsStore 里的reducers里的 setNamelist 方法
this.props.dispatch({
type: '

本文介绍如何在DVA框架中创建并连接全局model,以实现组件间的共享状态管理。通过实例展示models目录下的全局model配置过程及其在页面组件中的应用。
最低0.47元/天 解锁文章
2584

被折叠的 条评论
为什么被折叠?



