The image path is not being properly passed from Pinia to the component

Currently, I am in the process of developing a card carousel that features a Spotify-style thumbnail with an image as the background and text overlaid on top. The content for this carousel is stored in a Pinia store, which will eventually be connected to Firebase. However, while attempting to set the image background, I encountered the following error:

GET http://127.0.0.1:5173/%60$%7B%7Bcontent.image%7D%7D%60 404 (Not Found)

Below is a condensed version of my store code where the important bits are highlighted:

export const useContentStore = defineStore('contentStore', {
  state: () => {
    return {
      guides: [{
        title: 'XX',
        date: 'X',
        description: "X",
        image: './assets/images/content/thumbnail.png',
        id: '1',
      }]
    }
  }
})

This is where I attempt to access the image path:

<template>
  <div class="card">
    <img class="card-image" src="{{content.image}}"/>
    <h1 class="title">{{content.title}}</h1>
    <h2 class="subtitle"></h2>
  </div>
</template>

<script setup>
/*
  store
*/

import { useContentStore } from "@/stores/contentStore";

const contentStore = useContentStore();

/*
  props
*/

const props = defineProps({
  content: {
    type: Object,
    required: true,
  },
});
</script>

Here's where the cards are being called:

<template>
  <div class="guides-container">
    <h2 class="title">Guides</h2>
    <div class="guides-list">
      <GeneralCard
        v-for="(content, index) in contentStore.guides"
        :key="content.id"
        :content="content"
      />
    </div>
  </div>
</template>

<script setup>
/*
  imports
*/

import GeneralCard from "@/components/GeneralCard.vue";

/*
  data
*/
const contentStore = useContentStore();

</script>

I suspect the issue lies in transferring the string through the store to the template, but I'm unsure how to resolve it. I've attempted escaping characters, using template literals on both the stored path and the image tag, experimented with URL() function, and confirmed that the image path itself is correct (as it works when plugged directly into the image tag). Any assistance would be greatly appreciated!

Answer №1

The src attribute in the image tag is not correctly defined. The correct way to define it is:

<img class="image-card" :src="content.picture"/>

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

Troubleshooting Laravel API Eloquent Where Clause inconsistencies when integrated with Vue

Question: Why is my where clause not working as expected? I am utilizing a Laravel API in conjunction with Vue (using Vuex) for my project. Here is the Controller function: public function specific_client(Request $request) { $id = $request ...

How can I reset the validation method on a form when the first input field is clicked on? (Utilizing the jQuery Ajax Form Plugin and Magnific

Utilizing the jQuery Ajax Form Plugin in conjunction with the magnific popup plugin ajax type to update content dynamically. This is the form structure: <form method="post" action="/contact" id="contact_form"> <d ...

Vue - the <script setup> element is unable to execute scripts

I have a functional widget from Atlassian that works as expected when used in an HTML file: <html lang="en"> <head> <script data-jsd-embedded data-key=<key> data-base-url=https://jsd-widget.atlassian.com src=https://jsd-w ...

managing the speed at which animated gifs are loaded and played

I am facing a challenge with a slideshow that features multiple animated gifs. Each slide is equipped with its own animated gif. My goal is to ensure that the animated gifs play in synchronization with the timeline I have set up in photoshop, starting fro ...

Perform a series of database queries one after the other, ensuring they are completed before

Although the database queries themselves are working fine, I am facing an issue with executing them sequentially in Node. Here is an example of the queries I need to execute in order: DELETE FROM myTable; INSERT INTO myTable(c1, c2, c3) VALUES (x, y, z); ...

The error message "TypeError: jQuery(...).ready(...) is not a function" indicates that

Although this question has been asked before, none of the answers seem to solve my specific issue. I am attempting to run a small piece of jQuery code (as I am just starting to learn it). jQuery(document).ready(function(){ jQuery('.comtrig') ...

Refreshing a component within a route using React/Redux

On my basic CRUD screen, I have a list of rows with the usual edit link as follows: <Link to={"/appointment/"+appointment.id+"/"}>Edit</Link> The route setup is like this: <Route path="/appointment/:id" component={AppoModal} /> When ...

Is it possible to conceal the dates from past months in the datepicker plugin?

Currently, I am utilizing a datepicker tool from jQuery UI and adjusting its CSS to suit my requirements. My goal now is to hide any dates that are not currently active, specifically those displayed from other months. I am unsure if this can be achieved ...

Utilizing AMAZON_COGNITO_USER_POOLS in conjunction with apollo-client: A comprehensive guide

Struggling to populate my jwtToken with the latest @aws-amplify packages, facing some challenges. Encountering an error when attempting to run a Query: Uncaught (in promise) No current user It seems that when using auth type AMAZON_COGNITO_USER_POOLS, I ...

javascript encounter surprise issue

While diving into my code, I encountered an error. $('.log').prepend('<div class="symbol sublog"> অনুগ্রহ করে একটি প্রতীক যুক্ত করুন (`~!@#$%^&*()_+-={}|[]\;:",./< ...

Transform a string representing a specific time frame into a Unix timestamp using jQuery or JavaScript

I am trying to generate a Unix Timestamp for each date/time string that is generated within a foreach loop. Can anyone provide guidance on how to convert the string Mon Aug 08 2016 10:09:42 GMT+0100 (BST) into a Unix Timestamp to facilitate comparison? O ...

Integrating SignalR with Vue and Vuex for Real-Time Communication

I have been attempting to establish a connection between a SignalR hub and a Vue component, but so far I have not been successful. I have searched extensively for solutions by googling "vue with signalr" and reading through numerous links, even going as fa ...

Encountered an npm compilation error - Unable to locate module: bootstrap-theme.css

I recently updated all the dependencies in my JavaScript program without making any changes to my components or index.js file. However, when I run npm run build I encounter an error with index.js related to bootstrap-theme.css: Failed to compile. Modul ...

Angular Error TS2339: The property 'car' is missing from type 'Array of Vehicles'

Encountering Angular Error TS2339: Property 'vehicle' is not found on type 'Vehicle[]'. The error is occurring on data.vehicle.results. Any thoughts on what could be causing this issue? Is the problem related to the Vehicle model? I hav ...

Exploring the world of ColdFusion CFCs, Cross-Origin Resource Sharing

I am currently working on implementing a form submission to a remote server. The approach I am taking involves running the HTML locally and using AJAX to post data to the remote server. The setup includes a form, JavaScript code, and a ColdFusion Componen ...

Creating a Typescript interface that allows for the addition of unknown dynamic variables

When creating an interface, I want to have a mix of known variables and dynamic variables. Consider this initial interface definition: export interface ApplicationData { applicant?: ApplicantData; application_unit?: ApplicationUnit; inte ...

Calculate the total cost for each row in a table by multiplying the quantity and price using jQuery, then display the result

I'm encountering an issue with my table row calculations involving price and quantity. The calculation results show up correctly in the console, but when I try to display them back on the table, the total sum of the first row gets duplicated into all ...

Angular Material Slider is failing to display properly

I am struggling to get the Angular Material Slider to render correctly in my project. Here is the code I have been using: <div class="row formField" ng-cloak> <div class="col-md-2"> <div>送貨日期</div> & ...

Angular components for selecting options and checkboxes

Is there a simpler way to achieve multiselect by placing checkboxes inside select options? Here is an example of my HTML code... <md-input-container> <md-select ng-model="clients.regions" placeholder="Select a region"> <md-option ng-r ...

What is the method for determining the size of a WeakMap?

I am working with a WeakMap that looks like the following: let newObj = new WeakMap(); let key1={"a":1}; let key2={"b":2}; let key3={"c":3}; newObj.set(key1,"value1"); newObj.set(key2,"value2"); newObj.set( ...