首页 > 其他分享 >tsx 实现slot插槽

tsx 实现slot插槽

时间:2024-09-13 21:35:25浏览次数:1  
标签:slot scss 插槽 tsx child import slots

tsx 实现slot插槽

  • 父组件
<template>
    <div class="component-name">
        <child>
            <template #default="scope">
                <div>default</div>
                <div>{{ scope.a }}</div>
            </template>
            <template #myself>
                <div>sdfsdfsf</div>
            </template>
        </child>
    </div>
</template>

<script setup lang="ts">
import { ref, reactive, computed, onMounted, nextTick } from 'vue';
import child from './components/child';
</script>

<style lang="scss" scoped></style>

  • 子组件
import { defineComponent, PropType, h, computed, ref, watch } from 'vue';
import type { Reactive, Ref } from 'vue';
import styles from '../scss/child.module.scss';
import '../scss/child.scss'; //这引入的样式是全局的,会影响其他页面其他组件

export default defineComponent({
    setup(props, { slots }) {
        console.log(slots, 'slots');
        return () => {
            return (
                <>
                    {/* slots 直接访问模板函数,并且可以传入scope变量作用给模板 */}
                    <div class={styles.child}>{slots.default?.({ a: '23234' })}</div>
                    <div class={styles.child}>{slots.myself?.()}</div>
                </>
            );
        };
    }
});

标签:slot,scss,插槽,tsx,child,import,slots
From: https://www.cnblogs.com/jocongmin/p/18412927

相关文章

  • tsx css class样式如何使用
    参考代码import{defineComponent,PropType,h,computed,ref,watch}from'vue';importtype{Reactive,Ref}from'vue';importstylesfrom'../scss/child.module.scss';import'../scss/child.scss';//这引入的样式是全局的,会影响其......
  • vue3 内置特殊元素<slot> 与 插槽 Slots
    vue官网内置特殊元素<slot>插槽Slots<slot><slot>元素是一个插槽出口(slotoutlet),标示了父元素提供的插槽内容(slotcontent)将在哪里被渲染。Vue模板里的<slot>元素会被编译到JavaScript,因此不要与原生<slot>元素进行混淆。<slot>元素可以使用nameat......
  • Vue3:具名插槽
    有时在一个组件中包含多个插槽出口是很有用的。举例来说,在一个 <BaseLayout> 组件中,有如下模板:<divclass="container"><header><!--标题内容放这里--></header><main><!--主要内容放这里--></main><footer><!--底部内容放......
  • tsx 基本使用方式案例、tsx 使用class 方式
    tsx子组件、tsx使用class方式tsx组件代码import{defineComponent,PropType,h,computed,ref,watch}from'vue';importtype{Reactive,Ref}from'vue';importstylesfrom'../scss/child.module.scss';//函数局部组件实现constmyDiv=......
  • Signals & slots
    #!/usr/bin/python3#-*-coding:utf-8-*-"""ZetCodePyQt5tutorialInthisexample,weconnectasignalofaQSlidertoaslotofaQLCDNumber.Author:JanBodnarWebsite:zetcode.comLastedited:January2017"""i......
  • tsx defineComponent emits 实现
    emits定义结构和使用子组件import{defineComponent,PropType,h,computed,ref,watch}from'vue';exportdefaultdefineComponent({name:'PageF',props:{render:{type:Function,required:true//......
  • 基于mediapipe和pyttsx3技术实现一个姿态识别语音播报器
    系列文章目录第一章Python机器学习入门之mediapipe和pyttsx3的结合使用文章目录系列文章目录前言一、mediapipe和pyttsx3是什么?二、使用步骤1.引入库2.读入数据总结前言在比赛准备时,由于比赛任务要求需要机器人在自主迅游中记录家庭成员的行为动作,并进行语音播报......
  • slot插槽灵活应变显示表单的顺序,多少
    <el-formref="moreForm":model="formInline"inline>      <el-rowtype="flex"class="flex-row":gutter="0">       <slotvue:head-list="headList[32]">       ......
  • vue3 tsx 测试几种使用方式
    总论tsxsetup里面定义了returndom元素,则optionsapi的render函数不生效options的render函数生效前提是setup里面不能returndomoptions的render里面可以直接使用this访问setup里面的数据或者ctxtsx一般最好用defineComponent包裹,这样响应式才能生效tsxdom语法使用{}......
  • SCHNEIDER TSXTIOAS170BDI35600 24VDC IN模块的优缺点
        SCHNEIDERTSXTIOAS170BDI3560024VDCIN模块作为工业自动化控制系统中的关键组件,具有多个显著的优点,这些优点使得它在各种工业应用场合中脱颖而出。以下是对该模块优点的详细阐述:高精度与稳定性:该模块能够高精度地接收和转换24V直流电压信号,确保信号的准确性。同......