如何通过Expo / React Native获取资源

时间:2020-06-14 00:09:57

标签: javascript reactjs react-native async-await expo

使用此代码:

 handleShortCapture = async () => {
      try {
        const photoData = await this.camera.takePictureAsync();
        this.setState({ capturing: false, captures: [photoData, ...this.state.captures] })
      } catch (e) {
        ToastAndroid.show(e)
      }

      const shibeAmount = Math.floor(Math.random() * 3 + 1);
      Speech.speak(`shibe amount: ${shibeAmount}`)

      try {
        const shibes = await fetch(`https://cors-anywhere.herokuapp.com/https://shibe.online/api/shibes?count=${shibeAmount}urls=false&httpsUrls=false`)
        const jsonShibes = await shibes.json()
        Speech.speak(jsonShibes.length)
      } catch(e) {
        Speech.speak(e.message)
      } 
    };

我可以听到 shibe金额短语,但是听不到 fetch 请求的响应;我想念什么?

0 个答案:

没有答案
相关问题