我有两个类Orders.js
和api.js
。我需要在api.js
中调用ShowAlertWithDelay
,但由于我已经有了默认导出mapStateToProps
,我无法使用另一个导出。下面是代码
Orders.js
class Order extends Component {
constructor(props) {
super(props);
getOrders: []
}
ShowAlertWithDelay = () => {
ShowToast("location",3,5000);
};
const mapStateToProps = (state) => ({
getOrders: state.User.getOrders ? state.User.getOrders : [],
deliveredorder: state.User.deliveredorder ? state.User.deliveredorder : [],
userData: state.User.userData ? state.User.userData : false,
selectedTabdeliverOrder: state.User.selectedTabdeliverOrder ? state.User.selectedTabdeliverOrder : false
});
export default connect(mapStateToProps)(Order);
api.js
class Api {
if(resp.data.RouteCompleted == 206){
//Need to call ShowAlertWithDelay(); here
}
}
export default Api;
一个简单的方法是创建一个新文件来导出ShowAlertWithDelay显示带有延迟的警报.js
export const ShowAlertWithDelay = () => {
ShowToast("location",3,5000);
};
在Orders.js和api.js 中
import {ShowAlertWithDelay} from './ShowAlertWithDelay.js'
当您使用";导出默认值";然后像这样导入
import ShowAlertWithDelay from './ShowAlertWithDelay.js'
您可以通过在同一目录中创建index.js来索引Orders.js,但您有"ShowAlertWithDelay";独立于订单类
Orders.js
export const ShowAlertWithDelay =() =>{
ShowToast("location",3,5000)
}
export class Order extends Component {
//
}
index.js
export default { Orders } from './Orders.js'
export { ShowAlertWithDelay as Something } from './Orders.js'