小编All*_*ley的帖子

使用reactjs数组中的对象

我在构建应用程序index.js:1375时收到此错误警告:列表中的每个孩子都应该有一个唯一的“键”道具。在应用程序中(在src / index.js:7处),这是api的响应,我也有此问题,我也无法正确地将数组呈现为列表

(15) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
Run Code Online (Sandbox Code Playgroud)

这是我的代码

import React, { Component } from 'react'
import ImagesSearch from './ImagesSearch'
import axios from 'axios'

export class Images extends Component {
    constructor(props) {
        super(props);
        this.state = {
          data: [],
          searchquery: '',
        };
        this.onChange = this.onChange.bind(this)
        this.onSubmit = this.onSubmit.bind(this)
    }

    onChange(e) {
        this.setState({searchquery:e.target.value})
    }

    onSubmit(e) {
        e.preventDefault()
        this.images(this.state.searchquery)
        console.log(this.state.searchquery)
    }

    images(query) {
        return axios.get(`https://api.pexels.com/v1/search? 
            query=${query}+query&per_page=15&page=1`, {
              headers: { Authorization: `` } …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs

1
推荐指数
1
解决办法
51
查看次数

标签 统计

javascript ×1

reactjs ×1