如何将csv文件加载到nuxt vue组件中

时间:2019-01-19 10:44:14

标签: d3.js vue.js webpack nuxt

我目前正在尝试将csv文件加载到Nuxt页面中。文件夹结构在下面,并产生错误“无法加载资源:服务器响应状态为404(未找到)”

Project
  |
  +--pages
      |
      +--lesson
          |
         +--index.vue
         +--file.csv

import * as d3 from 'd3';
    export default{
    data(){
    return{
     dataset1:[]
    }

mounted(){

  d3.csv('file.csv', (myData) => {
  console.log('Mydta', myData);
  this.dataset1 = myData;
 })
 }
}     

我在nuxt文件夹中的Web Pack配置中添加了以下内容:

  build: {
/*
** You can extend webpack config here
*/
extend(config, ctx) {
  config = {
    module: {
      rules: [
        {
          test: /\.csv$/,
          loader: 'csv-loader',
          options: {
            dynamicTyping: true,
            header: true,
            skipEmptyLines: true
          }
        }
      ]
    }
  }
 }
}

预先感谢

1 个答案:

答案 0 :(得分:0)

我最近遇到了一个相同的问题,最终使用了@nuxt/content模块-像一个魅力一样,甚至不需要包含d3(通常是解析CSV文件的首选)。

相关问题