Skip to content

How do I import csv file? #8271

Answered by tony19
Djordjenp asked this question in Q&A
May 22, 2022 · 3 comments · 4 replies
Discussion options

You must be logged in to vote

Install @rollup/plugin-dsv as a dev dependency:

npm i -D @rollup/plugin-dsv

...and configure Vite to use it:

// vite.config.js
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import dsv from '@rollup/plugin-dsv' 👈

export default defineConfig({
  plugins: [
    vue(),
    dsv(), 👈
  ],
})

Then importing a .csv file would produce the object array, as you were expecting:

<script>
// MyComponent.vue
import csv from './filmList.csv'
console.log(csv) // => [{'name':'Parasite','year':'2019','href':'parasite-2019','src':'film-poster/4/2/6/4/0/6/426406-parasite-0-460-0-690-crop.jpg'}]
</script>

demo

Replies: 3 comments 4 replies

Comment options

You must be logged in to vote
2 replies
@Djordjenp
Comment options

@ghysc
Comment options

Answer selected by Djordjenp
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@craigyu
Comment options

@wyq730
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
7 participants