我每次都使用material-ui react-redux.store
数据。
使用小数据可以正常工作,但是使用大数据
数据,我观察到多个组件调用。
import React from 'react';
import { Switch, Route } from 'react-router-dom';
import PropTypes from "prop-types";
import { bindActionCreators } from "redux";
import { connect } from "react-redux";
import axios from "axios";
import {
vehiclefetchAction,
vehiclefetchInactiveAction,
} from "dan-actions/VehicleActions";
import { playTransitionAction } from 'dan-actions/UiActions';
import {
Vehicle,
AddVehicle,
EditVehicle,
ViewVehicle
} from '../pageListAsync';
import Parent from './Parent';
import GlobalVariable from "../../path/global";
const branch = "VehicleDemo";
const baseApiUrl = GlobalVariable.BASE_API_URL;
class VendorPage extends React.Component {
componentDidMount() {
this.handledata();
}
handledata() {
this.props.loadTransition(false);
const userDetails = JSON.parse(localStorage.getItem("userDetails"));
axios
.get(baseApiUrl + "v1/vehicles", {
headers: { Authorization: userDetails.token }
})
.then(response => {
var activeData = response.data.activeData;
var inactiveData = response.data.inactiveData;
if (activeData !== undefined) {
this.props.fetchData(activeData, branch);
// console.log(activeData)
}
if (inactiveData !== undefined) {
this.props.fetchInactiveData(inactiveData, branch);
}
this.props.loadTransition(true);
})
}
render() {
return (
<Parent>
<Switch>
<Route exact path="/app/settings/vehicles" component={Vehicle} />
</Switch>
</Parent>
);
}
}
VendorPage.propTypes = {
fetchData: PropTypes.func.isRequired,
fetchInactiveData: PropTypes.func.isRequired,
loadTransition: PropTypes.func.isRequired,
};
const mapDispatchToProps = dispatch => ({
fetchData: bindActionCreators(vehiclefetchAction, dispatch),
fetchInactiveData: bindActionCreators(vehiclefetchInactiveAction, dispatch),
loadTransition: bindActionCreators(playTransitionAction, dispatch),
});
const CrudTbFormDemoMapped = connect(
mapStateToProps,
mapDispatchToProps
)(VendorPage);
export default CrudTbFormDemoMapped;
这是我的组件代码,被多次调用。 为什么会这样?
所有数据都可以毫无问题地获取,但是当我刷新时,我得到很多错误页面调用。