'ref' 未定义 no-undef 我想尝试从 firebase 存储加载图像

'ref' is not defined no-undef I would like to try to load image from firebase storage

我正在使用 React 并尝试从 firebase 存储中获取图像 URL,并显示该图像。 但 'ref' 未定义 no-undef 发生了。

https://firebase.google.com/docs/storage/web/create-reference

官方说“ref()是用来获取图片的URL”

firebaseconfig.js

import firebase from 'firebase/app'
import 'firebase/firestore'
import 'firebase/auth'
import "firebase/storage"

  // Your web app's Firebase configuration
  // For Firebase JS SDK v7.20.0 and later, measurementId is optional
  var firebaseConfig = {
//connection information
  };
  // Initialize Firebase
  firebase.initializeApp(firebaseConfig);
  firebase.firestore();

export const storage = firebase.storage();

  const getImage = () =>{
    ref = storage.ref().child('/img/thumbs/super_potato.jpeg');
    ref.getDownloadURL().then((url) => {
      document.getElementById('image').src = url;
    });
  }

  return (
      <div className="container section project-details">
            <img id = "iamge" />
</div>

你在给它赋值之前没有定义 ref

变化:

ref = storage.ref().child('/img/thumbs/super_potato.jpeg');

let ref = storage.ref().child('/img/thumbs/super_potato.jpeg');

您可以在 eslint

上阅读有关 no-undef 的更多信息