Vue components: Using `object[key]` as a prop does not trigger reactivity

I'm attempting to bind a value from an Object into the prop of a Component, but unfortunately it is not reacting as expected. Despite using $this.set, the reactivity issue persists. Below is my template:

<div class="grid">
  <emoji-card v-for="name in shuffledEmoji"
    :name="name" :ticked="tickedEmoji[name]" :key="name"      
    @click="tickEmoji(name)"
  />
</div>
  • shuffledEmoji: Array<String>

In this scenario, tickedEmoji is an Object with string keys and boolean values. The tickEmoji function sets tickedEmoji[name] for that specific name to be true:

  methods: {
    tickEmoji (name) {
      this.$set(this.tickedEmoji, name, true)
    }
  },

The function gets triggered successfully, but the Component fails to register the changes.

Child component structure:

<template>
  <div class="card" @click="$emit('click')">
    <img draggable="false" :src="`/static/blobs/${name}.png`">
    <img v-show="ticked" class="green-tick" draggable="false"
      src="/static/ui/green_tick.png">
  </div>
</template>

<script>
export default {
  name: 'emoji-card',
  props: ['name', 'ticked']
}
</script>

Can you identify how I am going wrong here? The child component does not reflect the updates when tickEmoji is called.

Answer №1

After experimenting, I discovered that by removing the initialization code within the beforeCreate function, the issue was resolved. If anyone has any insights on why this particular change had such a significant impact, I would greatly appreciate your input.

  async beforeCreate () {
    let {blobs} = await (await fetch('http://localhost:3000/api/blobs')).json()

    // initializing tickedEmoji map (problem solved when loop is removed)
    for (let key of blobs) {
      this.tickedEmoji[key] = false
    }

    this.emoji = blobs
  }

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

At what point in time does the LoadingFrameComplete event in Awesomium typically happen?

According to the documentation from Awesomium, the event WebView.LoadingFrameComplete is triggered when a frame finishes loading. This description seems somewhat ambiguous. Does this event coincide with the JavaScript load event of the window? Or perhap ...

What can be done to resolve the issue of 'this.state.*.map' not being a function

I am encountering an issue while trying to export a single row from my component import React, {Component} from 'react'; class TableRow extends Component { state = { row: [] }; componentWillMount() { this.setState({row: this.props.chil ...

What is the best way to save a JSON stream to a file in Node.js?

I am facing an issue with writing a complete JSON object to a file as it is received. Currently, I am using const file = fs.createWriteStream('./example.file'); var inputStream = JSON.parse(generatedData); fs.write(inputStream+"\n"); The d ...

What could be causing the data in getServerSideProps to be altered?

After fetching data from an API and passing it to index.js using getServerSideProps, I noticed that the prop array is initially in order by rank [1, 2, 3, etc]. Here's an example of the data: [ {rank: 1, price: 123}, {rank: 2, price: 1958}, {rank: ...

Manipulating and transforming data through Puppeteer's iterative process into an object structure

As a beginner with the puppetteer library, I'm trying to iterate through Amazon reviews and save each comment as an object. Although my code seems to be functioning, it only retrieves the first comment and then stops. async function scrapeProduct(ur ...

Seamless side-to-side navigation

Currently, I am working on a website that has horizontal overflow instead of the common vertical scroll. While everything seems to be functioning properly, I need to enhance the user experience by adjusting the amount scrolled to move larger sections of th ...

Once I've located the correct document, how can I search for the object with the specific date and then modify it in mongoose?

I am currently working on creating a heatmap using react-d3-heatmap, and the data structure required for this is [{date: Date, count: Number}]. Below is the schema I have set up for this model. const HeatMapSchema = new mongoose.Schema({ user: {type: ...

Learn how to execute JavaScript code in Selenium without launching a web browser

I am currently using the Selenium API for web scraping on pages that contain JavaScript code. Is there a way to retrieve the code without having to open a web browser? I am still learning how to use this API Is this even feasible? ...

Execute with jQuery using Multiple Attribute Selector

I am attempting to input numeric values using a keyboard. My issue is as follows: the keyboard has an "Accept" button, and I have multiple text fields. I want to assign a different action for each text field. I attempted to use multiple attribute selector ...

Incorporate CloudKit JS into Vue Application

I want to integrate CloudKit JS into my new Vue project so I can access its functions from any component within my app. As a newcomer to Vue, I appreciate your patience with me. :) Currently, I attempted adding the following code snippet in main.js: var ...

What is the best way to include an image link in a JSON file using Nuxt.js?

I am working with nuxtjs and I have a file named data.json in the root directory. I am trying to add an image link in this JSON file, but it is not recognizing it. Here is my code: { "id": 1, "cardImg": "./assets/images/ima ...

Experiencing difficulties establishing a connection between the React client and Node.js server using SocketIO

I am currently getting familiar with socketIO and have successfully set up a basic nodejs server. However, I am facing an issue where my nextJS app is unable to connect to the server as expected. Despite no errors being displayed, the messages that should ...

Tips for displaying only a list of folders in elfinder, a jquery file management plugin

Currently, I am working on enhancing the features of a file manager plugin that allows users to manage their folders effectively. One key functionality of the plugin is the ability for users to share specific folders with others. However, if a folder has n ...

Having issues with django-autocomplete-light triggering JavaScript errors

My implementation of django-autocomplete-light is causing some issues with rendering autocomplete options. There is a section on the website where it functions perfectly, but in another section, it only works partially. The autocomplete options display c ...

Anomalous Link Behavior on iOS

I am encountering a strange issue with links on the provided website in iOS: When I try to tap on the links under the "Galleries" menu, such as "Benny," nothing happens. It appears that Safari is trying to load the new page, but then it fails to do so. H ...

Modify the information on a page by clicking a button on a different page

I'm currently working on the design of a website that consists of two pages. The first page features a button, which when clicked should remove the hidden class from an element on the second page. I have searched extensively for a solution, but so far ...

AngularJS selection controls: checkbox and dropdown menus

Can someone provide an example that includes a dropdown menu and checkboxes? The options in the checkbox list should match the data in the dropdown. Once a value is selected from the dropdown, the corresponding checkbox option should be automatically chec ...

What is the process for utilizing an Angular service within a view expression?

Angular guidelines suggest utilizing Angular services and expressions: It is recommended to use services like $window and $location in functions called from expressions. These services offer a way to access global variables that can be easily mocked. - ...

How to troubleshoot window.location not functioning in PHP, JavaScript, and

There is a software that utilizes Ajax Get. However, the code provided below seems to be malfunctioning. What steps can I take to rectify this issue? Javascript snippet: <script> function purchase_item(itemID) { $.ajax({ ...

WebStorm displaying 'Unresolved filter' error while using Vue

Regardless of the filter I apply in my Vue templates, they are highlighted in green with the error message "Unresolved filter." What is the solution to this issue? Should I report it to WebStorm or is there a way to fix it myself? My filters are specified ...