vue3 中tsx组件化下的插槽写法

element-plus elpopover table在tsx中展示多余文本

tsx中写插槽

代码中css引入的unocss,加了自定义命名vue3

本文只是记录tsx的写法,代码运行需要自定义组件(实现tsx写法的组件)

代码片段

<script setup lang='tsx'>
const column: TableColumnProps<Item>[]=[
        {
            label: '编号',
            prop: 'id'
        },
        {
            label:'示例',
            render:(row)=> {
              const slots = {
                reference: () => <div class="vue3-truncate vue3-cursor-pointer">这里在popover中展示的内容,鼠标放上去就可以</div>,
              }
              return (
                <ElPopover v-slots={slots} width="650px" popper-class="poperClass" effect="light">
                  <span>条码</span>
                </ElPopover>
              )
            }  
        }
    ]
</script>

<template>
<NiTable :columns='column' :data='data' />
</template>
对于Vue 3和TSX的父组件,你可以按照以下步骤进行操作: 1. 首先,确保你已经安装了Vue 3和相关的TypeScript支持。你可以使用Vue CLI来创建一个新的Vue项目,并选择TypeScript作为项目的模板。 2. 创建一个父组件的.vue文件,例如`ParentComponent.vue`,并在其编写组件的模板、样式和逻辑。 3. 在`.vue`文件,使用`<script lang="ts">`标签来指定该组件使用TypeScript进行开发。 4. 在`<script>`标签,定义组件的Props、Data、Methods等属性和方法,并按照需要进行类型声明。例如: ```typescript <script lang="ts"> import { defineComponent } from 'vue'; export default defineComponent({ name: 'ParentComponent', props: { message: { type: String, required: true } }, data() { return { count: 0 }; }, methods: { incrementCount() { this.count++; } } }); </script> ``` 5. 在模板使用父组件的数据和方法。例如: ```html <template> <div> <h2>{{ message }}</h2> <p>Count: {{ count }}</p> <button @click="incrementCount">Increment</button> </div> </template> ``` 6. 在其他地方使用父组件。例如,在另一个组件引入父组件并使用它: ```tsx <template> <div> <parent-component message="Hello from parent component"></parent-component> </div> </template> <script lang="ts"> import ParentComponent from './ParentComponent.vue'; export default defineComponent({ components: { ParentComponent } }); </script> ``` 这样,你就可以在Vue 3使用TSX编写父组件,并在其他组件引入和使用它了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值