@ozo/react-rock
Version:
React 移动端开发脚手架,基于CRA3,通用、开箱即用。
51 lines (42 loc) • 1.3 kB
JavaScript
import { observable, action } from 'mobx';
// import { ApiUrls } from '@/api';
import Store from '@/stores/Store';
/**
* DemoListStore 示例代码
*/
class DemoListStore extends Store {
articleListCount = -1;
articleList = [];
constructor(rootStore) {
super();
this.rootStore = rootStore;
//设置需要存储到本地字段
this.persistParam('articleList');
}
showToast(msg) {
this.rootStore.UIStore.showToast(msg);
}
setArticleList(data) {
this.articleList = data;
}
setArticleListCount(count) {
this.articleListCount = count;
}
// 获取数据,示例代码
getDataInfo() {
// const url = ApiUrls.GET_ARTICLE_LIST;
// return this.sendGet(url, {}, { loading: true }).then((res) => {
return import('@/mock/articleList.json').then((res) => {
this.rootStore.UIStore.setLoading(true);
setTimeout(() => {
this.setArticleListCount(res.total);
this.setArticleList(res.data);
this.rootStore.UIStore.setLoading(false);
this.showToast('数据加载完成!');
}, 2000);
});
}
}
export default DemoListStore;