【前端10】vue3中使用handsontable动态加载数据

<template>
    <el-container>
      <el-header>
        <p class="title">用户管理 User Management</p>
        <el-input v-model="input" size="large" placeholder="Please input" :prefix-icon="Search" />
        <el-button>Export</el-button>
      </el-header>
      <div class="main">
        <hot-table ref="hotTableComponent" :settings="hotSettings"></hot-table>
      </div>
    </el-container>
  </template>
  
  <script setup lang="ts">
  import { ref, onMounted } from 'vue';
  import { Search } from '@element-plus/icons-vue';
  import { HotTable } from '@handsontable/vue3';
  import { registerAllModules } from 'handsontable/registry';
  import 'handsontable/dist/handsontable.full.css';
  import { get_user_data } from '@/service/admin';
  
  const input = ref('');
  const  hotTableComponent = ref(null); // Handsontable 实例的引用

  const hotSettings = ref({
    data:[],
    licenseKey: 'non-commercial-and-evaluation',
    height: 'auto',
    rowHeights: 30,
    manualColumnResize: true,
    stretchH: 'all',
    colHeaders: [
      '用户',
      'cost center',
      '订阅模式',
      '应收金额',
      '实收金额',
      '有效期',
      '金额是否确认',
    ],
    columns: [
      { data: 'user_name', type: 'text' },
      { data: 'cost_center', type: 'text' },
      { data: 'subscription_model', type: 'text' },
      { data: 'amount_receivable', type: 'text' },
      { data: 'paid_amount', type: 'text' },
      { data: 'period', type: 'text' },
      { data: 'confirmed', type: 'text' },
    ],
    dropdownMenu: true,
    contextMenu: true,
    multiColumnSorting: true,
    filters: true,
    rowHeaders: true,
    autoColumnSize: true,
  });

  onMounted(async () => {
  try {
    const apiData = await get_user_data(); // 替换为实际的接口调用方法
    hotSettings.value.data=apiData.list
    //data.value=apiData.list
    hotTableComponent.value.hotInstance.loadData(apiData.list)
    console.log(hotSettings.value.data,"hotSettings.value.data ");
    
  } catch (error) {
    console.error('Failed to fetch user data:', error);
  }
});
  
  // 注册 Handsontable 的模块
  registerAllModules();
  </script>

主要通过 hotTableComponent.value.hotInstance.loadData(apiData.list)s

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值