Use
defineEventHandler
- Returns a
csv
string from theexampleData
array.
ts
const exampleData = [
{
car: 'Audi',
price: 40000,
color: 'blue',
},
{
car: 'BMW',
price: 35000,
color: 'black',
},
{
car: 'Porsche',
price: 6000,
color: 'green',
},
]
export default defineEventHandler(async () => {
try {
const { csv } = await pergelChangeName()
.json2csv()
.use({
data: exampleData,
})
return csv
}
catch (error: any) {
return error.message
}
})
- Returns the HTTP response
Content-Disposition
with theattachment
value and thefilename
value ascsv-[timestamp].csv
.
ts
const exampleData = [
{
car: 'Audi',
price: 40000,
color: 'blue',
},
{
car: 'BMW',
price: 35000,
color: 'black',
},
{
car: 'Porsche',
price: 6000,
color: 'green',
},
]
export default defineEventHandler(async (event) => {
try {
const { setResponseCsv } = await pergelChangeName()
.json2csv()
.use({
data: exampleData,
})
await setResponseCsv({
event,
csv: true,
})
}
catch (error: any) {
return error.message
}
})
changeName
changeName
is the name of your project. Please change it to your project name.