[英]How to get path of image in the Laravel 9 with Vue 3 and Typescript
everyone, I install laravel 9 with vue3, and everything was working fine but then when I try to get the image in my APP.Vue component here is the code for image <img src="logo.png" alt="Logo Image" />
it did not load on browser giving an error "image not found" inside the browser console.大家,我用 vue3 安装 laravel 9,一切正常,但是当我尝试在我的 APP.Vue 组件中获取图像时,这里是图像<img src="logo.png" alt="Logo Image" />
的代码<img src="logo.png" alt="Logo Image" />
它没有在浏览器上加载,在浏览器控制台内出现“找不到图像”错误。
I tried multiple solutionsns but they did not work for me.我尝试了多种解决方案,但它们对我不起作用。
please help请帮忙
bellow it the vite.congig.ts file.下面是 vite.congig.ts 文件。
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import vue from '@vitejs/plugin-vue'
export default defineConfig({
plugins: [
laravel([
'resources/scss/app.scss',
'resources/js/app.ts',
]),
vue({
template: {
transformAssetUrls: {
// The Vue plugin will re-write asset URLs, when referenced
// in Single File Components, to point to the Laravel web
// server. Setting this to `null` allows the Laravel plugin
// to instead re-write asset URLs to point to the Vite
// server instead.
base: null,
// The Vue plugin will parse absolute URLs and treat them
// as absolute paths to files on disk. Setting this to
// `false` will leave absolute URLs un-touched so they can
// reference assets in the public directly as expected.
includeAbsolute: false,
},
},
}),
],
});
My App.vue(where i am accessing the image)我的 App.vue(我在哪里访问图像)
<template>
<header>
<Menubar
class="
layout-topbar
w-full
fixed
h-5
shadow-1
bg-white
border-noround border-none
"
:model="showSidebar ? null : sidebarItems"
>
<template #start>
<img src="logo.png" alt="Logo Image" />
</template>
<template #end v-if="showSidebar">
<p>Welcome, Muhammad </p>
</template>
</Menubar>
</header>
<main>
<Menu
class="layout-sidebar border-noround border-none border-right-1"
:model="sidebarItems"
v-if="showSidebar"
/>
<div class="layout-main">
<div class="layout-content">
<div class="px-5 py-7">
<router-view />
</div>
</div>
<div
class="layout-footer flex align-items-center justify-content-between"
>
<small>Copyright© <b>spantiklab.com</b> Car Rent</small>
<small>Version 3.0</small>
</div>
</div>
</main>
</template>
<script lang="ts">
import { Options, Vue } from "vue-class-component";
import { useStore } from "vuex";
@Options({
components: {},
})
export default class App extends Vue {
showSidebar: Boolean = true;
mounted() {
window.onresize = () => {
if (window.innerWidth < 960) {
this.showSidebar = false;
} else {
this.showSidebar = true;
}
};
}
sidebarItems = [
{
label: "General",
items: [
{
label: "Dashboard",
to: "/admin",
},
{
label: "Reservations",
},
{
label: "Types and Rates",
},
{
label: "Extras",
},
{
label: "Office Locations",
},
{
label: "Users",
},
],
},
{
label: "Car Inventory",
items: [
{
label: "Cars",
},
{
label: "Availability",
},
],
},
{
label: "Options",
items: [
{
label: "Rental Settings",
},
{
label: "Payments",
},
{
label: "Checkout Form",
},
{
label: "Notificatins",
},
{
label: "Terms",
},
],
},
{
label: "System Options",
items: [
{
label: "General",
},
{
label: "API Keys",
},
{
label: "Email Settings",
},
{
label: "SMS Settings",
},
{
label: "Languages",
},
{
label: "Login & Protection",
},
{
label: "Countries",
},
{
label: "Corn Jobs",
},
],
},
{
label: "Profile Settings",
items: [
{
label: "Profile",
},
{
label: "Log out",
},
],
},
]
}
</script>
the image is in resources/js/images图片在资源/js/images
check your img url in brower.在浏览器中检查您的 img 网址。 img url relative path is the public or static file. img url 相对路径是公共或静态文件。 please use import or move img to public/static file!请使用导入或将 img 移动到公共/静态文件!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.