export default class getCfgShow {
static fetch() {
return new Promise(function(resolve, reject) {
fetch('访问的文件路径').then(function (response) {
return response.json();
}).then(function (data) {
resolve(data);
}).catch(function (e) {
reject(e);
console.log("Oops, error");
});
});
}
}
用的时候可以调用:this.cfgShow();
import getCfgShow from '../SystemConfig/SystemConfig/CfgShow/cfg.js';
cfgShow(){
// let { dispatch } = this.props;
getCfgShow.fetch().then(function (response) {
var data = response.NetTabCfgShow;
localStorage.setItem('NetTabCfgShow', data);
}).catch(function (response) {
console.log(response);
});
}
这里可以使用redux,但是由于只存一个字段,数值是0和1,这里使用缓存来完成