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
Table of contents Install Tomcat with Docker Use ...
Copy code The code is as follows: <span style=...
Linux File System Common hard disks are shown in ...
1. Use the df command to view the overall disk us...
Background <br />Students who work on the fr...
The detailed process of configuring the MySQL dat...
As the Internet era becomes more mature, the deve...
routing vue-router4 keeps most of the API unchang...
1. Introduction Elasticsearch is very popular now...
This article shares the specific code of Vue impo...
Ubuntu 20.04 has been released, bringing many new...
1. Create a new user wwweee000 [root@localhost ~]...
The first step is to unzip the compressed package...
Songti: SimSun Bold: SimHei Microsoft YaHei: Micr...
Table of contents 1. Install the proxy module 2. ...