Is it possible to pass the image source to a Vue.js component through a

I am encountering an issue while trying to display an image in the designated location within display.vue. Even though {{ someText }} returns the correct file path (../assets/city.png), the image is not being output correctly.

Here is how my code looks:

<template>
    <example :someText="'../assets/' + stamp + '.png'"></example>
</template>

<script>
import example from './example.vue'

export default {
    name: "",
    data() {
        return {
            stamp: "city"
        }
    },
    components: [
        example
    ]
};
</script>

The code for example.vue is as follows:

<template>
    <img :src="someText" />
</template>

<script>
    export default {
      name: "example",
      props: ["someText"]
    };
</script>

Answer №1

To ensure compatibility, modify the casing of your props:

Web browsers are case-insensitive when it comes to HTML attribute names, automatically converting uppercase characters to lowercase. Therefore, if you're working with in-DOM templates, prop names written in camelCase should be changed to kebab-case format (source)

Here's how it should be done:

<template>
  <example :some-text="'../assets/' + stamp + '.png'"></example>
</template>

Answer №2

A similar situation happened to me as well. When dealing with a file named example.vue, consider trying the following approach:

<template>
    <img src="../assets/city.png" />
</template>

If this does not produce the expected result, you may want to attempt using the full pathway instead:

<template>
    <img src="src/assets/city.png" />
</template>

In my case, the issue was that the image could not be found at ../assets/city.png, but it was successfully located at src/assets/city.png

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

Using Vue to access values in v-model:

I need to implement validations for a form with 30 fields by using getters and setters. However, it seems I cannot have computed and data values with the same name. Some examples suggest that setting the model and the computed property as the same can wor ...

Stale reference to element detected in Protractor despite implementation of conditional wait

I am encountering an issue within the beforeEach function of my test class. Sometimes, clicking on the usersTab works fine, but other times it results in a StaleElementReferenceException. I have experimented with using protractor.ExpectedConditions such as ...

What is the best way to utilize moment.js for adding days while excluding weekends?

I have a requirement to set a default follow-up date that is two days ahead of the current date. The existing code for this functionality is as follows: const Notify = moment().add(2, 'days').toDate(); Now, I need to modify this code to exclude ...

Ways to implement Formik to output a boolean value?

Currently, I am facing an issue retrieving a value from Formik. While it works perfectly fine with a Textfield component, I am unable to fetch the value of my switcher (which is a boolean). The setup for my file and switcher looks like this: <div clas ...

Can a single value be stored in a table using a radio button?

I have created an HTML table that is dynamically generated from a database. I am using a for loop to populate the table. However, I am facing an issue where each radio button in the table holds only one value. What I actually want is for each row to have ...

issue with visibility of checkbox in material ui table row

In a separate file called TradesTable.js, I have created a table using Material UI for my React app. const DummyTableRow = (props) => { let myRows = props.trades.map((trade, index) => { return <TableRow> <TableRowColumn ...

Apologies, but Discord.js is unable to access the property "user" of a null object

I am facing a perplexing issue that I cannot seem to wrap my head around. The function works perfectly on one server but fails on another. Below is the snippet of code in question: const user = message.author; let servericon = message.guild.iconURL; let se ...

Error: Failed to load chunk (VueJS + Webpack) - Please try again

Currently, I am working on a project that involves Wordpress and VueJS 3 with a Webpack 5.43 build. Whenever a new version is deployed on the production environment and a visitor already has a tab open on the website, I encounter the following error messag ...

The console is displaying an undefined error for _co.photo, but the code is functioning properly without any issues

I am facing an issue with an Angular component. When I create my component with a selector, it functions as expected: it executes the httpget and renders a photo with a title. However, I am receiving two errors in the console: ERROR TypeError: "_co.photo ...

Arranging files based on the total amount of a particular category within an array of related documents

Here is the structure of my main schema: _id: id, random: random, cards: [objectId, objectId, ...] //ref to cards An example of a card in the schema: _id: id, random: random, random: random, clicks: 15. I am looking to sort the top schema base ...

The functionality of the Bootstrap toggle button seems to be malfunctioning

I'm having trouble with the toggle button in my Bootstrap code. When I resize the window, the toggle button appears but clicking on it doesn't do anything. This is my first time using Bootstrap, so I might have made some silly mistake. Any assist ...

Accessing html form elements using jQuery

I'm having trouble extracting a form using jQuery and haven't been able to find a solution. I've tried several examples, but none of them display the form tags along with their attributes. Here is a sample fiddle that I've created: Sam ...

Unable to retrieve value from a hidden input field using JavaScript

My goal is to retrieve a value from a hidden inputbox using JavaScript. However, I am encountering issues where sometimes I receive an "undefined" error and other times there is no output at all. When I utilize alert(document.getElementById('hhh& ...

The issue of jQuery, Ajax, and MVC6 parameters becoming null after an Ajax request has been identified

Hello everyone, I am a beginner in asp.net core, c# and MVC 6. Currently, I am facing an issue with sending data over ajax to my controller. function sendAjaxData() { $.ajax({ url: "AjaxWithData", // using hardcoded value for testing purpose type ...

Error message: Attempting to access the 'path' property of an undefined variable results in TypeError while utilizing cloudinary services

I am currently attempting to upload a file from React to an Express server, but I keep encountering this error TypeError: Cannot read property 'path' of undefined The method I am using involves React for transferring/uploading the file to the ...

Learn how to efficiently disable or enable a button in Angular depending on the selected radio button

In order to disable the button when the remarks are marked as failed. Here is an example scenario: Imagine there is an array containing two to four items. First example: ITEM 1 -> FAILED -> Remarks (required) ITEM 2 -> FAILED -> Remarks (r ...

Ways to specify an unused parameter within a function

As I work on my code, I encounter the need to separate the key and value from a request params object in order to validate the value using ObjectID. To achieve this, I decided to iterate over an array of entries and destructure the key and value for testin ...

Using TypeScript to import a Vue 2 component into a Vue 3 application

Recently, I embarked on a new project with Vue CLI and Vite, utilizing Vue version 3.3.4 alongside TypeScript. In the process, I attempted to incorporate the vue-concise-slider into one of my components. You can find it here: https://github.com/warpcgd/vu ...

Is your CPU overheating due to IE7, encountering script issues, and need help with debugging

My current web design project is running smoothly on all Mac browsers and Windows Firefox, Chrome, and IE 8. However, I'm facing significant issues with IE 7. Despite having the CSS almost in place with a few adjustments needed, the CPU usage spikes t ...

What methods can I use to integrate Cheerio with CSS Manipulation?

I've been working on a web scraping project using axios, cheerio, and express. However, every time I attempt to run the project, it encounters errors. For testing purposes, I am using a test page from my friend's website. Here is the code snippe ...