Preface I am planning to write a When building the architecture, prepare to use But I encountered a problem using Find the problem First, I wrote a basic import Component from 'vue-class-component' import VanUIComponent from '@packs/common/VanUIComponent' import { VNode } from 'vue' import { Prop } from 'vue-property-decorator' import { CardShadowEnum } from '@packs/config/card' @Component export default class Card extends VanUIComponent { @Prop({ type: String, default: undefined }) public headerPadding !: string | undefined @Prop({ type: String, default: '' }) public title !: string @Prop({ type: String, default: CardShadowEnum.Hover }) public shadow !: CardShadowEnum public static componentName = 'v-card' public get wrapperClassName(): string { const list: string[] = ['v-card__wrapper'] list.push(`shadow-${ this.shadow }`) return list.join(' ') } public render(): VNode { return ( <div class={ this.wrapperClassName }> <div class="v-card__header" style={ { padding: this.headerPadding } }> { this.$slots.title ? <slot name="title" /> : <div>{ this.title }</div> } </div> <div class="v-card__body"> <slot name="default" /> </div> <div class="v-card__footer"></div> </div> ) } } When using this <template> <v-card> <template #title>1111</template> </v-card> </template> <script lang="ts"> import Vue from 'vue' import Component from 'vue-class-component' @Component export default class Components extends Vue { } </script> <style lang="scss" scoped> .components__wrapper { padding: 20px; } </style> I found that after rendering, the browser does not replace I searched Baidu and Google for a day but couldn't find an explanation. After reading the official documentation carefully, there was no similar hint. The documentation of the solve The next day, I was still struggling with this and looked up how to write in Unwilling to give up, I changed the search text and finally found a solution. I changed the code to: ... public render(): VNode { return ( <div class={ this.wrapperClassName }> <div class="v-card__header" style={ { padding: this.headerPadding } }> { this.$slots.title ?? <div>{ this.title }</div> } </div> <div class="v-card__body"> <slot name="default" /> </div> <div class="v-card__footer"></div> </div> ) } ... Check out the browser rendering again: Problem Solving postscript When using This is the end of this article about the problem of Vue+tsx using slot not being replaced. For more relevant Vue+tsx slot not being replaced, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Linux firewall status check method example
>>: Detailed explanation of Linux less command examples
This article example shares the specific code of ...
Table of contents Overview Example Why is it need...
1. A container is an independently running applic...
Project scenario: Dark Horse Vue project manageme...
Table of contents Basic usage of Promise: 1. Crea...
Table of contents Docker Compose usage scenarios ...
What is routing? Routing refers to the activity o...
Table of contents 1.Nuxt server-side rendering ap...
After creating a container locally, you can creat...
The shell script sets access control, and the IP ...
Table of contents 1. Slow query configuration 1-1...
Table of contents Preface 1. Custom focus command...
Table of contents 1. Description 2. Download rela...
Overview This article will introduce the MVC arch...
The installation process is omitted (I installed ...