错误:
未捕获(承诺中)类型错误:无法读取未定义的属性(读取“路径”)
根据我的测试,
import { getStorage, ref, uploadBytesResumable, getDownloadURL }
from "https://www.gstatic.com/firebasejs/9.1.1/firebase-storage.js";
import { getDatabase, set, child, get, update, remove }
from "https://www.gstatic.com/firebasejs/9.1.1/firebase-database.js";
const realdb = getDatabase();
错误是因为 firebase-storage 中的 ref( ) 函数与 firebase-database 中的 ref( )
不同但是我只能导入其中一个函数,那么该怎么办呢? 要保存 downloadURL,我需要 (firebase-storage) 和 (firebase-database)。
您可以像这样重命名其中一个导入:
import { getStorage, ref as storageRef } from "https://www.gstatic.com/firebasejs/9.1.1/firebase-storage.js";
然后确保您在代码中使用
storageRef()
而不是 ref()
进行存储。
在使用某些存储功能之前,请确保您已经导入并初始化了应用程序。
import { initializeApp } from "firebase/app";
initializeApp(firebaseConfig);