我正在嘗試對我的數(shù)據(jù)庫提出請求;我使用 userid 作為屬性來過濾響應(yīng)。使用的“myid”來自我的 redux。執(zhí)行此請求時,我有一個有點(diǎn)奇怪的數(shù)組作為答案,并且我對用戶發(fā)布的帖子沒有正確答案。請求響應(yīng):import axios from 'axios'import { NavigationEvents } from 'react-navigation'import Post from '../components/Posts/post'const mapStateToProps =({user}) => { return { email:user.email, name:user.name, myid:user.id }} class MyPosts extends Component { state={ posts:[], } getPosts = () =>{ console.log(this.props.myid) axios.get(`/posts?userid=${this.props.myid}.json`) .then( res => { console.log(res) const rawPosts = res.data const posts =[] for (let key in rawPosts) { posts.push({ ...rawPosts[key], id: key }) } this.setState({ posts: posts}) } ) .catch (err => console.log(err)) } componentDidMount = () => { this.getPosts() } render () { return ( <View style={styles.containerAll}> <NavigationEvents onDidFocus={() => this.getPosts()} /> {console.log('Log do Return', this.state.posts)} <View> <Header style={{ backgroundColor: '#006bb3' }}> <Left> <Icon name="md-menu" type='Ionicons' style={{ color: "#FFF" }} onPress={() => this.props.navigation.openDrawer()} /> </Left> <Body> <Title>Meus anúncios</Title> </Body> <Right> </Right> </Header> </View> </View> </View> ) }}我正在使用:反應(yīng)-redux”:7.1.1,還原”:4.0.4,反應(yīng)”:16.8.6,反應(yīng)原生“:0.60.4”,axios”:0.19.0,
axios響應(yīng)請求返回一個奇怪的數(shù)組
溫溫醬
2022-01-13 17:32:35