消息关闭
    暂无新消息!

数据获取与页面刷新问题

问题作者 : 小馒头2017-06-28发布
//store
import {observable, action} from "mobx";
import {request} from "../utils/axios"

export default class EconomyState {

    @observable economyList;

    constructor() {
        this.economyList = [];
    }

    //列表展示
    async getEconomyList() {
        const {data} = await request(
            {method: 'get', url: '/api/economy/list'},
            {},
            {message: '获取经济信息列表失败'},
        );
        this.setEconomyList(data);
    }

    @action setEconomyList(data) {
        this.economyList = data;
    }
}
//component
@inject("store")
@observer
class EconomyMain extends Component {

    constructor(props) {
        super(props);
        this.store = this.props.store.economyState;
    }

    state = {
        option: "map",
    };

    componentWillMount() {
        this.store.getEconomyList();
    };
    
    render(){
    console.log(this.store.economyList)
    return(
    ...)
    }
}

问题就是打印出来的economyList为空,但是我打断点看了,获取到数据以后,第二次刷新页面economyList是有数据的,但是为什么没有再次打印出来,我也用了observer啊,导致我后面数据都获取不到!


1个回答