What are the best practices for utilizing Vue.js slot components and managing interactions between parent and child components?

Recently, I've been exploring the slot component feature of Vue.js with the aim of understanding how to manipulate component information using slots. I decided to create a simple code snippet in order to grasp the concept of slot components better. However, my initial attempt was unsuccessful.

I created two components: one main component called "ApptestMaster.vue" and another child component named "ApptestChild.vue". My intention was to display a list of information from the child component within the ApptestMaster component. Unfortunately, only the button is being displayed. Any suggestions would be greatly appreciated!

↓Below is the code for the main component "ApptestMaster.vue"

<template>
    <v-app>
        <ApptestChild name="hoge">
            <ul>
                <li>List1</li>
                <li>List2</li>
                <li>List3</li>
            </ul>
        </ApptestChild>
    </v-app>
</template>
<script lang="ts">
import {Component,Vue} from 'nuxt-property-decorator'
import ApptestChild from '~/components/ApptestChild.vue'

@Component({components:{ApptestChild},})
export default class ApptestMaster extends Vue{
    
}
</script>

↓And here is the child component "ApptestChild.vue"

<template>
    <div>
        <v-btn name="hoge" @click="onClick">Click</v-btn>
        <v-slot v-if="display"></v-slot>
    </div>
</template>

<script lang="ts">
import {Component,Vue} from 'nuxt-property-decorator'

@Component
export default class ApptestChild extends Vue{
    display:boolean=true;
    onClick(){
        this.display = !this.display
    }    

}
</script>

Answer №1

Your syntax is incorrect. There is no <v-slot> tag. The correct tag to use is <slot>

In order to utilize a slot in your ApptestChild component, you should include the following template:

<template>
  <div>
    <v-btn name="hoge" @click="onClick">Click</v-btn>
    <slot v-if="display"></slot>
  </div>
</template>

For more information, please refer to https://v2.vuejs.org/v2/guide/components-slots.html

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

Vue Component not Updating even though the URL is changing

Encountering a problem where the URL updates but the page does not refresh. On the homepage, I have a list of projects. When clicking on a project, it should lead to "website.com/project/project-1" and function correctly. However, at the bottom of that p ...

Vue .filter doesn't work with reactive data sources

I'm currently working on a project that involves creating a dynamic shipping estimate in a Shopping Cart. The challenge I face is retrieving shipping methods from an API endpoint and making the data reactive to update in real-time based on the selecte ...

Enhance your coding experience with TypeScript's autocomplete in Visual Studio Code

After migrating a project from JavaScript to TypeScript, I am not seeing autocomplete suggestions or type hints when hovering over variables in Visual Studio Code editor (Version 1.7.2). Even the basic example provided below does not display any auto-com ...

Using setState as a parameter in a personalized hook in React/Next.js while incorporating TypeScript

I encountered an issue with the following code snippet: import { useState, useEffect } from "react"; type Props = { setState: (value: string) => void; }; const useSomeCustomHook = ({ setState }: Props) => { useEffect(() => { se ...

Is it Possible for the Number Array Type to Not Be Recognized as an Array?

export class ... { single: any[] = []; multi: any[] = []; view: number[] = [700, 400]; ... <Removed for brevity> } Error Message: It says 'Type 'number[]' is not assignable to t ...

How to implement ngx-infinite-scroll in Angular 4 by making a vertically scrollable table

Looking for a way to make just the table body scrollable in Angular 4 using ngx-infinite-scroll. I've tried some CSS solutions but haven't found one that works. Any help or documentation on this issue would be greatly appreciated. I attempted th ...

Filter a Vue list based on a checkbox that can be either checked or unchecked

I am currently working on my Vue app and aiming to filter a list to display only entries that have been moderated. However, I am encountering an issue where when the checkbox is checked, I receive all the results that are true, and when the checkbox is un ...

What is the best way to showcase the data retrieved from axios in a Vuejs table?

I am new to Vuejs and encountered an issue while trying to display user information retrieved from API endpoints using axios. Below is the code snippet for fetching data: import axios from 'axios'; export default { data(){ return{ ...

I find that ChangeDetectionStrategy.OnPush does not function as anticipated

Exploring the performance boost of ChangeDetectionStrategy.OnPush in Angular 2 (detailed here) has been my recent focus. However, I've encountered an interesting scenario. In my code, I have the parent component AppComponent: @Component({ selector ...

Mastering asynchronous props handling with Vue 3's composition API

Starting Component: const { receiveData, deletePost, erasePhonebook, fetchCount, issue } = useSections(); const section = ref({}); receiveData(section_id).then((s) => { section.value = s; }); Sub Component: const { section } = defineProps({ secti ...

Vue - a guide on customizing a prop in a parent component

I have implemented a wrapper component that encapsulates a Quasar q-select element in the following manner: <template lang="pug"> q-select( :options="organisations" option-value="id" v-bind="$attrs&quo ...

Developing a type specifically for this function to operate on tuples of varying lengths

I am currently developing a parser combinator library and I am in need of creating a map function that can take N parsers in a tuple, along with a function that operates on those N arguments and returns a parser that parses into the return type specified b ...

Invent a customizable receptacle for component

I am working on a component and I want to be able to change the tag name of the container for that component, like this: <my-component tagName="section"></my-component> so that it renders like this: <section>... my inner component tags ...

Tips for creating an input box that only accepts floating point numbers:

I have a custom component - a text box that I am using in two different places. In one location, it accepts integers and in another, floats. For the integer validation (where dataType=2), I have successfully implemented it. However, for the float validat ...

An action in redux-toolkit has detected the presence of a non-serializable value

When I download a file, I store it in the payload of the action in the store as a File type. This file will then undergo verification in the saga. const form = new FormData(); if (privateKey && privateKey instanceof Blob) { const blob = new Blo ...

Unexpected token @ while using Angular2 with jspm and gulp for typescript compilation

Recently, I've delved into learning about Angular 2 and its accompanying technologies. In an attempt to create minified and "compiled" versions of my .ts files, I started using gulp-jspm-build. However, I encountered an error that has left me stumped. ...

Verify if the specified key is present in the type parameter and if it corresponds to the expected data type in the value parameter

I have a specific goal in mind: export interface GCLPluginConfig { [key: string]: string | number | boolean | Date | string[]; } export interface CorePluginConfig extends GCLPluginConfig { "core.lastUpdateCheck": Date; } export interface An ...

Unable to retrieve data from the array

I am encountering an issue while trying to fetch data from an array, as I keep receiving undefined Please refer to the image for a visual representation of my problem. I'm not sure what I might be overlooking, so any help would be greatly appreciate ...

Restricting access to tabPanel in tabView when a tab is clicked using Angular

In my tabview, I have multiple tabpanels and I am able to programmatically control it using the [activeIndex] property. However, I am facing an issue where I want to display an alert and deny access to a specific tab if a certain variable is set to false. ...

In Angular 5, a variable's value becomes undefined once it is subscribed to outside of its assigned

I keep encountering an undefined value when trying to assign the subscribed value to a variable in my code snippet below. service.ts getIpAddress() : Observable<any> { return this.http .get(this.Geo_Api) .map((response: ...