Vue.js slots do not automatically update when dynamic data is passed down from the parent component

Initially, I successfully pass a variable from the parent component to the slot of a child component where it is correctly displayed. However, when this variable changes in the parent, the change is not reflected in the child component. Below is my code snippet:

<template>
  <div>
    <v-client-table
     :columns="columns"
     v-model="data"
     :options="options"
     :class="{ 'ready' : isReady }"
    >
    <div slot="h__select">
      <input type="checkbox" @change="selectAll($event)" 
      :checked="allSelected" />
    </div>
 ....

The variable in question is "allSelected". How can I bind the "checked" attribute to the value of the "allSelected" variable? I have researched extensively but haven't found a solution. Any assistance would be greatly appreciated.

Answer №1

Implement the following method:

<template>
<!-- A high-level V-CLIENT-TABLE component -->
  <table>
    <thead>
      <tr>
        <th>
          <slot name="h__select" :allSelected="all" />
        </th>
        <!-- Display the header contents here -->
      </tr>
    </thead>
    <tbody>
      <tr v-for="(item,index) in items" :key="index">
        <slot :item="item" />
      </tr>
    </tbody>
  </table>
</template>

<script>
export default
{
  name: 'VClientTable',
  props:
  {
    items:
    {
      type: Array,
      default: () => []
    },
    columns:
    {
      type: Array,
      default: () => []
    },
  },
  data()
  {
    return {
      all: false,
    };
  },
  watch:
  {
    all(newValue, oldValue)
    {
      // Update checkboxes for all rows
    }
  }
}
</script>
<template>
<!-- Implementation of using V-CLIENT-TABLE -->
  <div>
    <v-client-table
     :columns="columns"
     v-model="data"
     :options="options"
     :class="{ 'ready' : isReady }"
    >
    <div slot="h__select" slot-scope="data">
      <input type="checkbox" @change="data.allSelected = !data.allSelected" 
      :checked="data.allSelected" />
    </div>
  </div>
</template>

<script>
export default
{
  name: 'ChildComponent',
}
</script>

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

Tips on triggering another action before a loop completes, involving AJAX

I've been struggling with this issue for quite some time now and I'm out of ideas. Can anyone offer assistance, please? All I want is to reload the current page after adding items to the cart. I've tried various methods like using count, pr ...

Encountering the error 'Cannot read property 'length' of undefined' while attempting to fetch data from a URL using node.js

While attempting to create a Discord-Bot capable of looking up definitions on urbandictionary, I encountered an error after trying to fetch the json from their api. const args = Array.prototype.slice.call(commandArgs); if (!args.length) { return m ...

Tips for creating a gradual fade-out effect on a bootstrap modal window

One issue I'm facing is with my modal dialog (#busyIndicator). It simply displays a message that reads "Please Wait". Sometimes, the operation it's tied to completes so quickly that the visual transition between showing and hiding the dialog beco ...

Activate the Bootstrap Jquery/Ajax inline editing feature by simply clicking on the Edit button

Seeking recommendations for a way to implement inline editing. When the edit button is clicked, I want the label's content to be replaced with an input text field that can be updated in my MySQL database. This is what my code looks like: <label s ...

`The Issue with Ineffective Slider Removal`

Below is the complete code: import React, { Component } from "react"; import "./App.css"; import Slider from "@material-ui/core/Slider"; import Typography from "@material-ui/core/Typography"; class App extends Compo ...

Looping through Vue custom events

When I use v-for to display components, the custom event update emitted by the child component is not triggered. However, when using standalone components, everything works fine. I am struggling to find a solution to this issue. Main.js import Vue from & ...

Is there a way to make a selected option stay selected in vue.js 2?

Here is the structure of my Vue component : <template> <select class="form-control" v-model="selected" :required @change="changeLocation"> <option :selected>Choose Province</option> <option v-for="option in o ...

Having trouble accessing a JSON object with Typescript in an Angular 2 project

Something strange is happening with my code. I am working with a JSON object: {"login":"admin","name":"Admin"} And this is the relevant part of my code: private _userData: User; ... private getUserData() { this._userInfoService.getUserInfo() ...

Adding text in a key value pair object can be easily achieved by specifying the key

I was able to transform two arrays into a key-value pair object. firstArray: [] = ['a','b','c','d'] secondArray: [] = [1,2,3,4] Below is the code used to accomplish this transformation: let dict = firstArray.map(fun ...

Show values in currency format with two decimal places

Is there a way to convert numbers like 1499 into 14.99 in jQuery? The raw numbers will always end in "99," such as "1999", "2499", "9999". I've come across code that rounds or assumes there are no decimals, but that's not what I need. var num = ...

Update the SQL database by transferring star ratings from a JSP file

Utilizing JSP to showcase information obtained from user queries, I have implemented a system where contextual data and the query itself are saved in a MySQL database using JDBC each time a new query is input. To enhance user interaction, I wanted to incor ...

Why is it not possible to incorporate a variable in HTML when using Vue.js?

Why am I encountering an error when trying to use location information in HTML? The error message is Uncaught (in promise) TypeError: Cannot set properties of undefined (setting 'geoLocationPlace'). What could be causing the variable 'geoLoc ...

Is there a way for me to retrieve SCSS color variables within the javascript of a Vue template?

I have a unique challenge in my application involving a component called Notification. To bring notifications to other components, I utilize the mixin method toast('message to display', 'color-variable'). My goal is to set the backgroun ...

Steps for inserting a script tag in an Angular component

My Angular/Typescript website needs to integrate a third-party script that generates a table. However, I'm facing issues with rendering the table within the home.component.html file. I've managed to embed the script, but it doesn't seem to ...

What causes a delay in the start of a child process in Node.js?

I am in the process of developing a global node command line program that can execute any console command I provide it with in a new console window, whether on a Windows or Unix system. The goal is for the program to exit after it spawns its process so tha ...

Iterate through a generic array to populate a table using ng-repeat

In the scenario I'm currently facing, I am working on creating a common reusable table structure using a directive. The goal is to display different JSON data in both the table header and body. Below is the controller code: angular.module('plun ...

Retrieve the currently displayed page on a bootstrap table

I'm currently utilizing the bootstrap table to showcase my data. One of the features I have added is a column with an edit button for each row. Upon clicking on the edit button, I open a bootstrap modal that displays the data from the corresponding ro ...

What is the best way to calculate the difference in days between two dates using Javascript?

While there are many questions similar to this one, I've noticed that most examples focus on calculating the absolute number of days difference. So, how exactly can I determine the number of relative days between a given date (in epoch seconds) and t ...

What is the best way to send an Angularjs variable to an id within an HTML input?

Currently, I am using angularjs ng-repeat to add checkboxes in the following manner: <div class="checkbox-circle" ng-repeat="t in tenders"> <input type="checkbox" checklist-model="contratacion.select" checklist-value="t.id" id="{{t.id}}"> ...

Assigning event to the body element

Is there a way to bind an event to the entire page, specifically the html or body tag? I am trying to achieve the following: document.addEventListener('mousemove', function() { alert('a'); }); I want an alert to be triggered whenever ...