Skip to content

Vue VtInput 文本输入 ​

文本输入列:常态显示纯文本,进入编辑态后在浮层里改,值实时写回行数据。

编辑态走 renderEditor,必须装 vtCellEditor 插件才会被触发。

示例 ​

微应用尚未挂载。

源码 ​

点击查看源码
vue
<template>
  <div class="demo-wrapper">
    <h3 class="demo-title">Vue VtInput 文本输入</h3>
    <div class="status-text">{{ status }}</div>
    <div style="width: 960px; height: 600px" class="demo-container">
      <VirtTableVue :columns="columns" :options="options" />
    </div>
  </div>
</template>

<script setup lang="ts">
import { VirtTableVue, type VueTableColumn, vtCellEditor } from '@virt-table/vue';
import { VtInput } from '@virt-table/vanilla/components';

// 单元格组件是与框架无关的列工厂:直接从 vanilla 引,返回的列可以原样交给 VirtTableVue
const ROW_COUNT = 5000;

const columns: VueTableColumn[] = [
  { key: 'id', title: 'ID', width: 80, align: 'center' },
  VtInput({ key: 'name', title: '姓名', width: 180, placeholder: '请输入姓名' }),
  VtInput({ key: 'email', title: '邮箱', width: 240, placeholder: '请输入邮箱', clearable: true }),
  VtInput({
    key: 'remark',
    title: '备注',
    width: 260,
    placeholder: '请输入备注',
    maxLength: 50,
    clearable: true,
  }),
  VtInput({ key: 'readonly', title: '只读列', width: 180, disabled: true }),
];

const list = Array.from({ length: ROW_COUNT }, (_, i) => ({
  id: i,
  name: `用户 ${i}`,
  email: `user${i}@example.com`,
  remark: i % 3 === 0 ? `备注信息 ${i}` : '',
  readonly: `不可编辑 ${i}`,
}));

const options = {
  list,
  itemKey: 'id',
  estimatedSize: 40,
  buffer: 4,
  border: true,
  textOverflow: 'ellipsis' as const,
  // 编辑态走 renderEditor,必须装 vtCellEditor 才会被触发
  plugins: [vtCellEditor()],
};

const status = `VtInput 单元格组件:${ROW_COUNT} 行(点击单元格编辑,支持 placeholder、clearable、maxLength、disabled)`;
</script>

相关 API ​

字段作用
maxLength最大输入长度

全量选项表见 单元格组件;公共选项 (placeholder / disabled / clearable / onChange)、asCell()、三类交互模型见 同页上方;列的通用字段见 列配置。

编辑态需装 vtCellEditor,见 插件机制。

上面的字段在 Vue 端原样透传(实例方法通过组件 ref 调用)。封装层特有的部分 —— 组件 Props、渲染函数返回 VNode、ref 转发了哪些方法 —— 见 Vue API。