1、安装依赖:npm install xlsx --save

2、引入:

// 导出表格  按钮点击后触发事件
const onBatchExport = () => {
  
    const column = [
    //数据表单
    {
      title: "ID", //表头名称title
      key: "id", //数据
      type: "text", //类型
    },
    {
      title: "景区ID",
      key: "scienceid",
      type: "text",
    },
    {
      title: "景区名称",
      key: "sciencename",
      type: "text",
    },
    {
      title: "二维码",
      key: "code",
      type: "image",
      width: 80,
      height: 80,
    },  
    {
      title: "二维码状态",
      key: "state",
      type: "text",
    },
    {
      title: "创建时间",
      key: "time",
      type: "text",
      width: 130,
      height: 80,
    },
  
  ];
 //将数据转化为字符串(list_data数据是接口数据,把名称换成自己的数据即可)
  let tableDatas = JSON.parse(JSON.stringify(datalists.value)); 
  let datas = tableDatas;
  table2excel(column, datas, "数据"); //表单数据名称
};

3、 结果:

 

 

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐