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 Preface 1. Parent component pas...
Error description When we install Docker Desktop,...
Table of contents Block-level functions Directly ...
Table of contents Overview 1. Develop the require...
Problem Description MySQL reports an error when s...
Table of contents Preface Style Function Descript...
The title images on Zhihu Discovery columns are g...
Preface Linux groups are organizational units use...
hash mode (default) Working principle: Monitor th...
Here is how to install Tomcat-8.5.39 on centos7.6...
question: Recently, garbled data appeared when de...
Example: tip: This component is based on vue-crop...
1. Create a test table CREATE TABLE `testsign` ( ...
Today, when verifying the concurrency problem of ...
Preface Execute the show create table <tablena...