如何从 console.log 访问此响应?

How do I access this response from the console.log?

通常,我用 fetch 更容易做到这一点,但这个包不使用 fetch。 我阅读了其他与我类似的问题,这是我尝试这样做的尝试:

SelectPhoto = () =>{
ImagePicker.openPicker({
}).then((imgResponse) => {
  console.log(imgResponse.path); <-- Trying to access the path
});
}

我不断收到 undefined,这是我的控制台日志结果:

0:{size: 745660, mime: "image/jpeg", height: 2960, width: 1440, path: "file:///storage/emulated/0/DCIM/Screenshots/Screenshot_20180617-173313.jpg"} length:1

谁能帮我解决这个问题?非常感谢!

您似乎在使用 react-native-customized-image-picker

根据他们的docs和你的console.log输出,你可以得到路径并设置为状态如下:

import React from 'react'
import ImagePicker from 'react-native-customized-image-picker'

class App extends React.Component {
  constructor (props) {
    super(props)

    this.state = { path: null }
    this.handleClick = this.handleClick.bind(this)
  }

  handleClick () {
    ImagePicker.openPicker({}).then(image => {
      const path = image[0].path

      this.setState({ path })
    })
  }

  render () {
    return <div onClick={this.handleClick}>Select image</div>
  }
}