Component的构造函数第二次不起作用

问题描述 投票:0回答:1

我有一个Component类:

class AutoPage extends Component {
constructor(props) {
    super(props);
    console.log("Auto is " + this.props.route.params.auto);
    this.state = {
        avto: this.props.route.params.auto,
    }
    this.array = [
        this.state.avto.PICTURE,
    ];

    for (let dopImage of this.state.avto.DOP_FOTO.VALUE) {
        this.array.push(dopImage);
        //console.log(avto);
    }
    }
}

我正在从另一个地方打开此组件:

<TouchableOpacity onPress={() => navigate('AutoPage', {
                auto: item
              })}>

这是我的抽屉导航:

 <Drawer.Navigator drawerContent={props => <CustomSidebarMenu {...props} />} width={Dimensions.get('window').width - 130}
  component={CustomSidebarMenu}>
  <Stack.Screen name="AutoListPage" component={AvtoListPageNav} />
  <Stack.Screen name="AutoPage" component={AutoPage} options={{ headerTitle: "GorodAvtoPrime", headerTitleAlign: "center" }} /> 
</Drawer.Navigator>

当我单击TouchableOpacity时,AutoPage打开并且其构造函数起作用。但是,当返回并再次单击TouchableOpacity时,将打开AutoPage,并且其构造函数不起作用。我正在this.props.route.params.auto中获取以前的数据。单击AutoPage时如何使TouchableOpacity的运行构造函数?

我有一个Component类:AutoPage类扩展了Component {构造函数(props){super(props); console.log(“自动为” + this.props.route.params.auto); this.state = {avto:this ....

react-native react-router react-navigation react-navigation-drawer
1个回答
0
投票

尝试一下:

© www.soinside.com 2019 - 2024. All rights reserved.