Retrieving information from various object keys using Vue.js

Currently, I am in the process of setting up a feature in my application where users can select an option from a list and the background of the app will change based on their selection.

Imagine having a list structured like this:

<li v-for="item in items">
    <label class="radio">
        <input type="radio" value="{{ item.name }}" v-model="itemSelection">
            {{ item.name }}
    </label>
</li>

The items array is stored in my store.js:

items: [
   {name: 'item1', img: 'placehold.it/200x200-1'}
   {name: 'item2', img: 'placehold.it/200x200-2'}
   {name: 'item3', img: 'placehold.it/200x200-3'}
],

When a user selects item1, I not only want to retrieve the name for display in the parent component using itemSelection, but also get the image link to use it in CSS for changing the body background. Since I'm new to Vue, I am figuring out how to implement this as part of my learning process!

Appreciate any guidance and suggestions you may have!

Answer №1

There are numerous methods to achieve this, such as:

observe : {
    selectedElement: function(value) { ... }
}

Here are a few examples. Feel free to explore this JSFiddle demo

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

Cease the progress of a Sequelize promise within an Express.js application

Exploring the realm of promises is a new adventure for me, and I'm still trying to grasp their full potential in certain situations. It's refreshing to see Sequelize now supporting promises, as it greatly enhances the readability of my code. One ...

Tips for organizing and concealing images within a Div for seamless transitions (no need for floats)

Currently, I am working on a grid layout for my website. My goal is to have 9 images load quickly, and then once the page has loaded, I want to fetch additional images, insert them into the image containers, and animate between them. While I understand how ...

Tips for correctly cloning a table row:

Currently, I am engaged with a Django project that involves incorporating a form within a table structure. <table name="mytable" id="table_purchase" role="grid"> <thead> <tr> <th class="text-center" hidden>No</th& ...

Filtering incoming data from a Firestore database: A step-by-step guide

I'm facing a challenge while trying to incorporate this filtering mechanism into my code. FILTERING An issue arises when I attempt to implement the following lines of code: function search(text: string, pipe: PipeTransform): Country[] { return CO ...

Calculate the number of views using Laravel and VueJS

Looking for assistance with tracking the number of visits to each article on my Laravel and Vue-based articles site. Previously used eloquent-viewable package in Laravel, but unsure how to implement in Laravel + Vue. Can anyone provide guidance on this? ...

Creating a distinct folder for every upload in Node.js using multer and shortid

Utilizing shortid for unique IDs for each upload along with multer for the post handler. I am uploading some input data as well as an image and aiming to store each upload inside "upload/XXXXX". The unique ID is generated in the app.post(...) and I am see ...

React's useState Hook: Modifying Values

I just started learning about React and React hooks, and I'm trying to figure out how to reset the value in useState back to default when new filters are selected. const [apartments, setApartments] = React.useState([]) const [page, setPage] = React.us ...

bing translator API: the variable text is translated with no content

I'm encountering an issue while working with javascript and PHP. The PHP code seems to run fine until it reaches the $curlResponse variable. From there onwards, all the subsequent variables ($xmlObj, $translatedStr, $translatedText) appear to be empty ...

Is there a way to determine the number of clicks on something?

I'm attempting to track the number of times a click event occurs. What is the best method to achieve this? There are two elements present on the page and I need to monitor clicks on both of them. The pseudo-code I have in mind looks something like ...

Automatically selecting the map center while using the Drawing Manager feature for placing markers

My application utilizes the Google Drawing Library. When a user clicks on the Add New Marker Button, the Drawing Manager is activated allowing the user to generate a marker by clicking anywhere on the map. Subsequently, the following listener is executed: ...

Is there a way to retrieve prName and prQty from the double array?

Is there a way to extract the values of prName and prQty from the 2D array? html <h1 v-for="item2 in productListAlaCarte" :key="item2"> <td>{{item2.prName}} {{item2.prQty}}</td> ...

Text being enveloped in a span tag

Currently, I have a table displaying a list of users with their corresponding roles. However, the roles column is sometimes wrapping before reaching the end of the line. The user list data looks like this: $scope.userList = [{ "id": 1, "name":"AB ...

Exploring the nuances of useEffect() functionality and the impact of extra re-renders

I ran some tests using a dummy component and noticed an unusual pattern in the console output: Rendering: 0 Triggered: 0 Rendering: 4 Triggered: 4 Rendering: 4 I'm having trouble figuring out why this is happening. On the first render, the foll ...

Issue: encountered a write EPIPE error while attempting to transfer a file to FTP via gulp

Whenever I try to deploy some stylesheets to a server using FTP, I encounter an error about 80% of the time. Here's the specific error message: Error: write EPIPE at _errnoException (util.js:1022:11) at WriteWrap.afterWrite [as oncomplete] (net.j ...

Implement rotation in Three.js that mirrors the functionality of Blender

Is there a way to permanently change the default rotation of a mesh in three.js after it has been loaded? For example, if I load a mesh with a rotation of 0,0,0, can I then rotate it 90 degrees on the X axis and set this new rotation as 0,0,0? It's i ...

Remove dynamically created elements from an AngularJS div

Is there a way to remove an item from the criteria list when clicking the delete button? Currently, only the filter is being refreshed and not the tables. Any suggestions on how to resolve this issue? HTML <ul class="list-unstyled"> <l ...

Error message: It seems the spatial reference for this ESRI object is missing

Currently, I am utilizing Esri GIS to load the center location from an address. However, I am encountering an issue as I am using a geocoder from Google to obtain longitude and latitude, which is resulting in the following error message: TypeError: this.s ...

Inject environment variable into SCSS file while using webpack

I'm new to webpack and I need help with reading a specific value, which is the env variable from the webpack.config.js file, in a sass file. This will allow me to have different CSS styles based on the environment. For example: If the env is set to ...

What is the procedure for invoking the delete route via ajax in Laravel?

When attempting to call a route resource with AJAX using the 'DELETE' method, an error is encountered (Exception: "Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException") along with the message "The DELETE metho ...

Employing the Vuetify validation feature for ensuring the accuracy of text input through manual

In my Vuetify web application, there is a search box that triggers validation rules when the user hits the search icon. If the input does not meet the regex specs, an error message is displayed. After validating the input, I perform a post request to chec ...