Having issues with setting the background image in vue.js

I've encountered an issue with calling a background-image in my scss file. Strangely, when I use the image tag img, everything works perfectly fine. However, as soon as I try to do the same within the <style> tags, it doesn't work and gives me the error message Can't resolve.

My setup involves Laravel and Vue, where everything is sent to the public folder. The image I'm trying to use is located in a folder named images within the public directory. On the other hand, all my Vue files are being directed to App.js inside the js folder under public.

I'm wondering what would be the correct method to call an image in Vue. Should I create an assets folder in my JS directory and place the image there?

Any assistance you can provide would be greatly appreciated. Laravel resources folder

https://i.sstatic.net/mXEPT.png

Laravel public folder

https://i.sstatic.net/vyKl1.png

<template>
    <div class="hero">
         <!-- works -->
        <img src="images/home/wow.webp" alt="img">
        <div class="hero-left">
            <h1>HI</h1>
        </div>
    </div>
</template>

<script>
export default {
    name: "Hero",
}
</script>

<style lang="scss" scoped>

    .hero {
        height: 90vh;
        width: 100%;
        background-image: url('../images/home/wow.webp'); // Does not work

        img {
            height: 100%;
            width: 100%;
        }
    }

</style>

Answer №1

It appears the paths you are using are different.

images/home/wow.webp does not match ../images/home/wow.webp.

Is there something I am overlooking?

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

An External Force is Disrupting My Jquery

Something seems off because everything was working perfectly fine until the FallingLeavesChristmas.min.js file stopped activating on this specific page. I initially thought it was an issue with the JavaScript itself, but that doesn't seem to be the ca ...

What is the best way to retrieve a JSON value when there are five variables with identical names?

I am in the process of creating a NSFW filter and I am looking for the results of the analysis. Specifically, I need to determine if the probabilities of "Pºrn" and "Hºntai" are greater than 0.7. However, I am encountering an issue with accessing the ind ...

Spring framework experiencing issues with loading CSS and JavaScript files

I'm facing an issue with my Spring-MVC application where the CSS and JS files are not loading even though they are correctly called. Can anyone help me figure out what I'm doing wrong? Resources folder: Project --> webapp --> resources - ...

AngularJS ui-router resolve function may not successfully return a custom value

While attempting to preprocess some data before navigating to my page, I am forcefully resolving a promise, converting it into a custom object, and then trying to return the custom object to my resolve object. .state("trip.detail", { ...

Get rid of the span tags and enclose the content within a parent <td> tag

i have this example: <td "class=name"> <span class="removed">one</span> <span class="added">two</span> </td> or maybe this: <td class=name> one <span class="removed">two</span> <sp ...

Dealing with Unhandled Promise Rejections in Express.js

I'm providing all the necessary details for this question, however I am confused as to why my callback function is returning an Unhandled Promise Rejection even though I deliberately want to catch the error: (node:3144) UnhandledPromiseRejectionWarni ...

Selecting an item with Material UI AutoComplete now automatically clears the value

After making a selection, I want to clear the value in the input field immediately. Currently, the value is cleared on blur but not upon selection. <Autocomplete disabled={showTextField} className="center-vertically" options={listOfDependencies ...

Best practices for efficiently updating state in React components

Currently, I am in the process of learning React and trying to grasp its concepts by practicing. One exercise I decided to tackle involves deleting an element from an array when a user clicks on it in the UI. Below is the code snippet that I have been work ...

Determining the total number of documents through aggregation while implementing skip and limit functionality

Is there a way to retrieve the total count of documents when implementing aggregation along with limit and skip in a query similar to the one below? db.Vote.aggregate({ $match: { tid: "e6d38e1ecd", "comment.top ...

Encountered an error while building CSS Modules for a Vue.js project

Working on a project in Vue.js, I decided to incorporate CSS modules for my local styles (for sass and scss). However, I continuously encounter a 'Failed to compile error' related to the CSS Loader validation process. Despite attempting various ...

Creating JavaScript classes based on JSON schemas

I have a JSON file containing information and data related to my work, presented in the following format: { "Employees":[ { "id": 1, "fullName": "Test Test" } ], "Infos":[ { "id": 1, ...

Mastering the map() and reduce() functions in JavaScript: A step-by-step guide

I have been working on a simple function to calculate prime numbers using a NoSQL database. Despite trying different approaches, I kept encountering an error stating that the value I was searching for is not defined. Any feedback or suggestions would be gr ...

What is the process of adding new fields to a model in TypeScript?

I have created a test.model.ts file: export interface ITransaction { description: string; transactionDate: string; isDebit: boolean; amount: number; debitAmount: string; creditAmount: string; } export class Transaction implements ...

utilize a Vue animation complete callback to incorporate a function

Can a function be passed inside the "done" callback for Vue animation? enter: function(e, done) { element.animate({ // ... }, duration, done) } Is there a way to ensure that the next "afterEnter" hook will still be called? If I wer ...

Can icons with an external path be utilized as a src in the manifest.json file within an Angular application?

Let's visualize the setup with two projects - project1 and project2. Each project has its own manifest.json file and the same apple-touch-icon-144x144.png file located in assets/icons directory. -project2 |_src | |_assets | | |_icons | | ...

Switching videos dynamically with JavaScript while utilizing Bootstrap to enable playback in a floating window

This is a piece of code that enables playing videos in floating windows using Bootstrap. However, I am looking to enhance the functionality by dynamically changing the video source using JavaScript. I tried using onClick() to modify the src attribute of th ...

Exploring deep nested writes within Prisma

Describing my database schema: model User { id Int @default(autoincrement()) @id createdAt DateTime @default(now()) email String @unique role String @default("user") sessions Sessio ...

Add a JavaScript library to the header directly from the body of a webpage, ensuring it is exclusive to a single

I am using the Google Charts JS library on a single page within my project, with external and global headers and footers. The head tags are located in a head.php file, where all required JS libraries are included. The structure of my pages is as follows: ...

Pass user input values to PHP via AJAX and display the outcome on a designated div

I am currently working on a project where I need to send an input value to a PHP script and display the returned value in a div using AJAX. However, I seem to be struggling with getting it to work properly. Any assistance or suggestions would be greatly ap ...

Transferring information from one page to the next

How can I efficiently transfer a large amount of user-filled data, including images, between pages in Next.js? I've searched through the Next.js documentation, but haven't found a solution yet. ...