"Exploring the power of Vue 1.0's source binding

Why isn't this working properly?

<img v-if="item.foto.src" v-bind:src="item.foto.src" width="{{item.foto.width}}" height="{{item.foto.height}}" />

Despite displaying the image, this code triggers an error in the browser.

<img v-if="item.foto.src" src="/{{item.foto.src}}" width="{{item.foto.width}}" height="{{item.foto.height}}" />

%7B%7Bitem.foto.src%7D%7D 404 (Not Found)

Answer №1

The initial one will not trigger a 404 error (assuming the path is correct, but you omitted the /), however, the second one will.

To fix this, you should use:

<img :src="'/' + item.foto.src">

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

Traversing a JSON object in JavaScript and comparing its key-value pairs with a specific pattern

When parsing a json object and comparing it against a specified pattern using regular expressions, the approach involves calling a function to create a new user account if the pattern is matched, otherwise, another function is called to display existing us ...

What is the process for displaying HTML page code received from an AJAX response?

My current project involves implementing JavaScript authentication, and I have a specific requirement where I need to open an HTML file once the user successfully logs in. The process involves sending an AJAX request with the user's username and passw ...

The Angular event handler fails to trigger change detection upon clicking

I am facing a simple problem where I have an element in a component's template with an ngIf condition and a (click) handler. Initially, the element is not rendered because the ngIf condition evaluates to false. What makes this interesting is that an ...

Incorporate JSON data into a subsequent AJAX call when coding in JavaScript

I am facing an issue where I need to use data returned from an ajax request to construct a string and then post it back using ajax. However, the variable I'm assigning the data to is not within the scope of the second request, resulting in a 'var ...

How to display an image stored in Laravel within a Nuxtjs application?

I'm trying to display all images that are saved in nuxtjs using Laravel's storage feature. <img v-for="(row, index) in files" :src="'storage/' + row" :key="index" alt="" width="150px" ...

The significance of JavaScript Namespace objects and the order in which scripts are included

I'm encountering an issue with JavaScript namespace conflicts. To organize my code, I've split my JavaScript objects into different files. Each file begins with a namespace declaration: var MySystem = MySystem || {}; However, when I include a ...

A guide to resolving the issue of invalid objects as a React child in Nextjs13

Seeking help on resolving an issue in Nextjs13, where I'm encountering the error "objects are not valid as a React child (found: [object Promise]). If you meant to render a collection of children, use an array instead" The scenario involves fetching ...

Is there a way to turn off linting while utilizing vue-cli serve?

I am currently running my project using vue-cli by executing the following command: vue-cli-service serve --open Is there a way to stop all linting? It seems like it's re-linting every time I save, and it significantly slows down the process of ma ...

problem with toggling audio on and off within a game

Currently, I am working on developing a 2D pacman clone using JavaScript and CSS. One of the features I'm trying to implement is background music with a mute option. However, I have encountered two issues in my code. When audio.muted is commented out, ...

Ending asynchronous tasks running concurrently

Currently, I am attempting to iterate through an array of objects using a foreach loop. For each object, I would like to invoke a function that makes a request to fetch a file and then unzips it with zlib, but this needs to be done one at a time due to the ...

How can we use jquery ajax to insert data into a JSON array?

I am struggling to identify the mistake in my AJAX code. Despite following tutorials online, I am unable to successfully POST data. Here is my HTML code: <h3>Input new data</h3> <form name="contact"> <input type="text" placeholder ...

Navigating into uncharted territories with each touch movement

Is there a way to change the background of an element as you drag your finger over it? It seems like using the touchmove event might work for this, but I'm having trouble getting the target element to change as I drag. While clientX and clientY value ...

Discover the absent day in an array of dates using JavaScript

Upon receiving an array of day dates from an API, the following structure is observed: 0:{date: "2016-11-17T00:00:00",…} 1:{date: "2016-11-18T00:00:00",…} 2:{date: "2016-11-19T00:00:00",…} 3:{date: "2016-11-21T00:00:00",…} 4:{date: "2016-11-22T00: ...

What is the best method for enabling CORS policy when making a fetch request from a Vue.js frontend to

I am currently facing an issue with my front-end code that is making a request to the back end (frontend is running on localhost:8081 and sending a request to localhost:8080) This is the front-end code snippet: <script lang="ts">import &a ...

Troubleshooting issue with .addClass in jqLite within Angular.js

I've been struggling recently to figure out why I can't use the .addClass method on jqLite. element.addClass('active') I have confirmed that element returns an array of HTML elements, and I have tested this multiple times. It's s ...

Send a pair of selected options from dropdown menus to a service using Angular

I have created a component that needs to pass two values from two separate dropdowns to my service on button click. Here is the code for my component: import { Component, Input, OnInit } from '@angular/core'; import { CategoryType } from '. ...

Issues with the backend API call functionality in Vue.js (front end) are causing

My current setup Frontend - Windows, running on port 3000 Backend - Ubuntu Linux in a Docker container, running on port 5000 Settings for Vue frontend in tsconfig.json export default defineConfig({ plugins: [vue(), vueJsx()], resolve: { alia ...

In React Router, redirect when location.state is not defined

import React, { useState } from "react"; import { Redirect } from "react-router-dom"; function Update(data) { if(!data.location.state) return <Redirect to="/"/> const [name, setName] = useState(dat ...

I continuously receive the error message "StripeInvalidRequestError: Insufficient funds in Stripe account" despite the fact that there are adequate funds available

I'm in the process of transferring funds from my test mode Stripe account to another connected Stripe account. The balance in my test mode account is sufficient and there are no pending funds. However, I keep encountering a "StripeInvalidRequestError: ...

What is the proper way for the curry function to function effectively?

Here's a function that I came across: function curry(fn) { var args = [].slice.call(arguments, 1); return function() { return fn.call(this, args.concat([].slice.call(arguments))); }; } I always thought this was the correct way fo ...