Unable to retrieve slots from child component's dynamic function in Vue2

When passing <slot name="success-mark"> to a child component, it is done as shown below:

<vue-dropzone ref="myVueDropzone"
  id="dropzone"
  :options="dropzoneOptions">
  <slot name="success-mark"><i class="fa fa-trash"></i></slot>
</vue-dropzone>

The child component contains a function that returns the template which includes the provided slot:

setPreviewTemplate(){
  return `
            <div class="dz-preview dz-file-preview">
                <div slot="image" class="dz-image" style="width: ${this.options.thumbnailWidth}px;height: ${this.options.thumbnailHeight}px">
                <img slot="thumbnail" data-dz-thumbnail /></div>
                <div slot="details" class="dz-details">
                    <div slot="size" class="dz-size"><span data-dz-size></span></div>
                    <div slot="name" class="dz-filename"><span data-dz-name></span></div>
                </div>
                <div slot="progress" class="dz-progress"><span class="dz-upload" data-dz-uploadprogress></span></div>
                <div slot="error-message" class="dz-error-message"><span data-dz-errormessage></span></div>
                <div class="dz-success-mark" slot="success-mark"><i class="fa fa-check"></i></div>
                <div slot="error-mark" class="dz-error-mark"></div>
            </div>
        `;
}

Efforts have been made to change the slot - success-mark, however, without success.

Expected Outcome

The child component should display the icon of a trash can (fa fa-trash).

Actual Outcome

Despite attempts, the child component continues to show the default check icon (fa fa-check) instead of changing to the trash can icon.

Where could the issue lie?

Answer №1

Modifying the child template like this

<slot name="success-mark"></slot><i class="fa fa-trash"></i>

will display the fa-trash icon (at least works with a non-dynamic template)

Just out of curiosity, could you demonstrate how you're implementing the result of setPreviewTemplate()? If I'm not mistaken, this is a case of a child component filling its own slot (not the parent providing content for the slot). Or was mentioning "and my child component has following function" a mistake? Did you mean to say "and my parent component..."?

Edit #1

Upon reviewing the source vue-dropzone, an idea comes to mind (although it might not be your preferred approach) - incorporate the icon into dropzoneOptions.

setPreviewTemplate(){
  return `
    <div class="dz-preview dz-file-preview">
       ...
       <div class="dz-success-mark" slot="success-mark">
         <i class="fa" :class="this.options.icon></i>
       </div>
       ...
}

Edit #2

Apologies if I have misunderstood, but it seems like the syntax is reversed.
The <slot> should be on the child element, so I would expect it in the output from setPreviewTemplate().
The parent supplies certain content that should possess the slot attribute, so maybe

<vue-dropzone ref="myVueDropzone"
  id="dropzone"
  :options="dropzoneOptions">
  <i class="fa fa-trash" slot="success-mark"></i>
</vue-dropzone>

and

setPreviewTemplate(){
  return `
    <div class="dz-preview dz-file-preview">
       ...
       <slot name="success-mark"><i class="fa fa-check"></i></slot>
       ...
}

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

Can one transition from using a callback to a returning Promise in order to implement an ErrorFirstCallback strategy?

In Node.js documentation, it is explained that an ErrorFirstCallback is triggered when the referred function fails. Error-first-callbacks in Node.js I have been practicing with this callback pattern and I am curious to know if it is possible to refactor i ...

Using Jquery and the cookie.split method to extract and eliminate a value from a cookie

I am trying to figure out how to remove a specific matching value from a cookie using JavaScript. I have written a script that loops over the cookie and checks for matches, but I can't seem to successfully remove just the matching value. Any tips on a ...

Intersecting Rays and Positioning Spheres with three.js

I have a scenario where ray intersection is functioning properly with tube geometry. Upon ray intersection, a small red sphere and a tooltip appear next to the cursor. The image below shows the scene without a header: When I include a header using a div e ...

Using AngularJS to dynamically apply a CSS class to message text depending on the HTTP post response

I am looking to implement a method for adding a CSS class to the text color of a message based on the response. Currently, I achieve this by: if (response.data.status == 201) { angular.element(document.getElementById("msg")).addClass("text-green"); ...

Having trouble with getting Express to automatically redirect to the main page upon user login

Currently, I am working on setting up a user login section. Despite the user_router successfully sending a JSON response, I am facing an issue with getting Express to send a new HTML page back to the client. The initial page offered is login.html, which co ...

Initiate the countdown when the button is pushed

Recently ran into an issue where a button triggers a command to a Perl script, causing the page to continuously load for 60 seconds. To provide users with transparency on when the Perl script will be finished running, I implemented a JavaScript countdown t ...

Disable the appearance of the scrollbar while maintaining the ability to scroll

Is there a way to hide the scrollbar on the body of an HTML page while still allowing scrolling with arrow keys or mouse wheel? I would appreciate any advice on this. Edit: I have received suggestions about using hover scrollbars and custom bars, as well ...

Quirks in TailwindCSS template literals behavior

Looking at this specific component: const SaleBadge = ({ textContent, badgeColor }) => { return ( <Badge className={`bg-${badgeColor}-200 hover:bg-${badgeColor}-300 animate-pulse align-middle ml-2`} variant="secondary"><Pe ...

Setting up Redux Saga in a modular format

I am currently using create-react-app for my project. As I now need redux-saga to handle async operations, I am encountering an issue with setting up sagas in a modular manner. When I say modular, I mean having one main sagas file that exports all the comp ...

Error encountered when trying to bind a popup to a Leaflet.js circle: NOT_FOUND_ERR: DOM Exception 8

I am currently working with Leaflet to create a popup over a circle I generated. The code snippet below illustrates my approach: var jsonString = '{"location":"edinburgh","topNouns":["track","love"],"eventWords":{"shot":1},"numberOfTweets":177.0, ...

Display the initial x list items without utilizing ngFor in Angular 2

In the template, there are 9 <li> elements, each with a *ngIf condition present. It is possible that 5 or more of them may return true, but the requirement is to only display the first 4 or less if needed. Priority is given to the order of the < ...

Utilizing ng-options within an ng-repeat to filter out previously chosen options

Facing a simple problem and seeking a solution. I am using ng-repeat to dynamically create select boxes with ng-options displaying the same values. The ng-repeat is used to iterate through model options. <div data-ng-repeat="condition in model.condit ...

Refresh ng-repeat array after implementing filter in controller

I am currently facing an issue with updating my table view when changing a variable that filters an array. The filter is applied in the controller based on the values of a specific variable called columnFilter. However, the filter does not reapply to updat ...

The response was blocked by CORB due to cross-origin content with a MIME type of text/html

Currently working with Laravel 9 and Vue js 3, I have two projects up and running on my localhost. One project is on port 8000 while the other is on port 8001. My goal is to fetch an image from port 8001 and display it on port 8000. However, CORS is blocki ...

What is the process by which Twitter constantly refreshes and updates your timeline?

Thank you for taking the time to read this. We are in the process of creating a web application and are exploring ways to update counters and information on the client side without relying on scheduled JSON updates. While timeouts can work, we are curious ...

Sorting and selecting isotopes, with the option to filter or unfilter

All day I've been struggling to find a solution for my isotope filtering issue. I'm using classes from the database to tag items, such as categories and dates, and allowing users to filter them. The tricky part is making these filters work like o ...

Exploring ways to access data stored in interconnected models, such as MongoDB and NodeJS

As a newcomer to querying, I attempted a unique exercise to practice but unfortunately did not achieve the desired outcome. I have three models: const userSchema = new Schema({ info1: String, info2: String }, const serviceSchema = new Schema( { name ...

Surprising lack of elements in the array

Apologies for the lengthy code, but unfortunately, I was unable to create a minimal example that reproduces the issue. The function below returns two arrays, with each cell containing a number: function VNtorus(R, r, nx, ny) { var Vertices = new Array ...

Having an issue with the return function in a jQuery $.ajax call

I am currently working with a $.ajax call that is structured like this: <script type="text/javascript"> $(document).ready(function () { $('#add_com_frm').submit(function (e) { e.preventDefault(); var $b ...

Troubleshooting issue with jest expect.any() failing to work with a custom class following migration from JavaScript to TypeScript

I recently made the switch to TypeScript in my project, and now some of my Jest tests are failing. It appears that the next function below is no longer being called with an AppError object, but with an Error object instead. Previously, the assertion expec ...