简体   繁体   English

Laravel 和 Vue:如何从 Vue 组件的公共文件夹中获取图像?

[英]Laravel and Vue: How do I get images from my public folder in a Vue component?

I am trying to get a logo image from my public folder in my laravel and Vue application.我正在尝试从我的 Laravel 和 Vue 应用程序的公共文件夹中获取徽标图像。 The file is called index.vue and have the following structure:该文件名为index.vue并具有以下结构:

<template>
    <div>
        <div class="header-container">
            <div class="header-content">
                <div class="logo-container">
                    <img :src="'/public/images/logo/black.png'" alt="logo">
                </div>
            </div>
        </div>

        <!-- Tell Vue where to render components -->
        <router-view></router-view>
    </div>
</template>

Here is the file structure and you can see that file exists and the path is correct:这是文件结构,您可以看到该文件存在且路径正确:

在此处输入图片说明

But when I switch back to the view it looks like this:但是当我切换回视图时,它看起来像这样:

在此处输入图片说明

I have also tried to call it the way I would in a blade template using {{ asset() }} , but this doesn't work and gives me a compiler error.我还尝试使用{{ asset() }}在刀片模板中调用它,但这不起作用并给我一个编译器错误。

How do I get this image to load in my Vue file?如何让这张图片加载到我的 Vue 文件中?

Not sure about vue + laravel.不确定 vue + laravel。 But, since its a relative path I dont think you need to bind anything.但是,由于它是一个相对路径,我认为您不需要绑定任何东西。

    <img src="/images/logo/black.png" alt="logo">
 


 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Laravel Vue - 如何让 vue 在公共文件夹中查找图像 - Laravel Vue - How to make vue to look for images in public folder Vue.js 获取 laravel 5.8 中的公用文件夹图像 - Vue.js Get public folder images in laravel 5.8 从 vue 组件 (Laravel) 中的公共文件夹导入 js 文件 - import js file from public folder in a vue component (Laravel) 我如何在不使用 vue-router 的情况下从 vue-component 重定向到 laravel 路由 - how do i redirect from vue-component to a laravel route without using vue-router 如何从laravel的images文件夹中删除我的图像? - How do I remove my image from images folder in laravel? 如何通过laravel axios将id从一个vue组件传递到路由器到另一个vue组件来获取数据 - How to get data by passing id into router from one vue component to another vue component through laravel axios 从 Laravel 刀片中的 Vue 组件获取值 - Get value from Vue component in Laravel blade 如何使用Vue访问laravel公共文件夹中的文件? - How to access files inside laravel public folder using Vue? 如何在 Vue 组件中显示从 Laravel 资源返回的数据? - How do I display data returned from Laravel resource in Vue Component? 如何从组件 Vue.js 和 Laravel 的数据库中获取复选框中的选定值? - How can i get the selected value in checkbox from database in component Vue.js with Laravel?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM