使用VUEJS显示从Firebase到Web的图像

发布于 2025-02-07 13:14:19 字数 1229 浏览 1 评论 0原文

我是Vue的新手,所以我不知道做这件事的多种方法。我想在我的应用程序上显示图像,该图像存储在Firebase存储中。我在HTML部分中的标签中调用一个函数,该功能返回图像的URL。我能够在控制台中显示图像,但是当应该返回URL时,它会给我一个“找不到模块”错误。

html

        <div>
            <p> Image gallery:</p>
            <img v-bind:src="getImgUrl()" >
        </div>

vue方法

         async getImgUrl() {

            // Create a reference to the file we want to download
            const storage = getStorage();
            const stationsRef = ref(storage, 'stations/cal.jpg');

            // Get the download URL
            const imageurl = await getDownloadURL(stationsRef)
            .then((url) => {
                return (url);
            })
            console.log(imageurl)
            return require(imageurl);           
        },

,这是它给出的错误:

Uncaught (in promise) Error: Cannot find module 'https://firebasestorage.googleapis.com/v0/b/rideservices-6a23d.appspot.com/o/stations%2Fcal.jpg?alt=media&token=d020eef5-88f3-4f64-aab0-fcf00d67bcd5'
    at webpackEmptyContext (app.a802d1ae56e3977d.hot-update.js:40:10)
    at Proxy.getImgUrl (serviceRequest.vue?b4a4:168:1)

如果我能获得帮助,这将非常有帮助。提前致谢!

I am new to Vue so I don't know many ways to do this. I want to display an image on my application which is stored in the Firebase storage. I am calling a function in the tag in the HTML part which returns the URL of the image. I am able to display the image in the console but it gives me a "Cannot find module" error when it is supposed to return the URL.

HTML

        <div>
            <p> Image gallery:</p>
            <img v-bind:src="getImgUrl()" >
        </div>

Vue Method

         async getImgUrl() {

            // Create a reference to the file we want to download
            const storage = getStorage();
            const stationsRef = ref(storage, 'stations/cal.jpg');

            // Get the download URL
            const imageurl = await getDownloadURL(stationsRef)
            .then((url) => {
                return (url);
            })
            console.log(imageurl)
            return require(imageurl);           
        },

and this is the error that it gives:

Uncaught (in promise) Error: Cannot find module 'https://firebasestorage.googleapis.com/v0/b/rideservices-6a23d.appspot.com/o/stations%2Fcal.jpg?alt=media&token=d020eef5-88f3-4f64-aab0-fcf00d67bcd5'
    at webpackEmptyContext (app.a802d1ae56e3977d.hot-update.js:40:10)
    at Proxy.getImgUrl (serviceRequest.vue?b4a4:168:1)

It would be really helpful if I can get help on this. Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文