在Vue3中使用 tsx / jsx + 插槽 (element-plus中的tsx写法与插槽)

 列配置项中代码如下

const columns = computed<any>(() => [{
    prop: "boilerPowerFeedback",
    label: t("totalData.boilerPowerFeedback") + t("totalData.hz"),
    width: 140,
    showOverflowTooltip: false,
    render: (scope: any) => (
      <>
        <el-popover
          width={220}
          placement="right"
          v-slots={{
            reference: () => <div>3366</div>,
            default: () => (
              <el-table data={gridData}>
                <el-table-column width="120" property="type" label={t("totalData.boilerPowerFeedback")} />
                <el-table-column width="100" property="name" label={t("totalData.hz")} />
              </el-table>
            )
          }}
        ></el-popover>
      </>
    )
  }]
const gridData = [
  {
    type: "1#锅炉",
    name: "0.0"
  },
  {
    type: "2#锅炉",
    name: "0.0"
  },
  {
    type: "3#锅炉",
    name: "0.0"
  }
];

Vue使用TypeScript和tsx(TypeScript JSX)语法实现`v-else-if`条件渲染,首先你需要确保安装了Vue CLI并配置了TS支持。以下是一个简单的步骤: 1. **安装依赖**:如果你还没有在项目中集成TypeScript,可以运行命令 `npm install typescript@latest @vue/cli-plugin-typescript` 或者 `yarn add typescript @vue/cli-plugin-typescript`。 2. **配置tsconfig.json**:打开`tsconfig.json`文件,添加对`.tsx`文件的支持,例如: ```json { "compilerOptions": { "jsx": "react", "allowJs": true, "types": ["node", "vue"], // 其他配置... }, "include": [ "src/**/*.ts", "src/**/*.tsx" ] } ``` 3. **创建组件**:在`.tsx`文件中编写你的组件,比如一个有条件渲染的例子: ```tsx <template> <div v-if="condition1"> This will be shown if condition1 is true </div> <div v-else-if="condition2"> This will be shown if condition2 is true and condition1 is false </div> <div v-else> Neither condition was met </div> </template> <script lang="ts"> import { Component } from &#39;vue&#39;; export default class MyComponent extends Component { public condition1: boolean = true; // 或者根据需要设置初始值 public condition2: boolean = false; // ... (如果需要,可以在这里添加数据计算等) mounted() { // 初始化逻辑或其他生命周期钩子 } } </script> ``` 4. **运行项目**:通过`npm run serve`或`yarn serve`启动Vue应用,现在你可以看到根据`condition1`和`condition2`值动态变化的渲染内容。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值