我正在使用这个导出到- csv 库来导出csv文件的项目,但是它返回一个错误"ExportToCsv不是构造函数“。我不知道有什么问题。希望你能帮我。
const ExportToCsv = require('export-to-csv');
module.exports.ExportToCsv = async (req, res) => {
try {
var data = [
{
name: 'Test 1',
age: 13,
average: 8.2,
approved: true,
description: "using 'Content here, content here' "
},
{
name: 'Test 2',
age: 11,
average: 8.2,
approved: true,
description: "using 'Content here, content here' "
},
{
name: 'Test 4',
age: 10,
average: 8.2,
approved: true,
description: "using 'Content here, content here' "
},
];
const options = {
fieldSeparator: ',',
quoteStrings: '"',
decimalSeparator: '.',
showLabels: true,
showTitle: true,
title: 'My Awesome CSV',
useTextFile: false,
useBom: true,
useKeysAsHeaders: true,
};
const csvExporter = new ExportToCsv(options);
csvExporter.generateCsv(data);
}catch(e) {
console.log(e);
}
}
发布于 2020-11-11 03:31:39
使用这些语句中的任何一条导入模块:
const ExportToCsv = require('export-to-csv').ExportToCsv
import { ExportToCsv } from 'export-to-csv';
代码的问题在于您正在导入和引用整个模块,您需要的是模块中的一个特定函数。错误正确地指出,变量ExportToCsv
不是构造函数,因为它引用了要导入的模块的整个导出对象。您需要使用的构造函数是从模块导出的对象上的一个属性,因此必须指向该特定属性。
https://stackoverflow.com/questions/64780026
复制相似问题