我目前正在尝试将一个csv文件加载到Nuxt页面中。文件夹结构如下,会产生错误"Failed to load resource: the server responded with a status of 404 (Not Found)":
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文件夹中的webpack配置中添加了以下内容:
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
}
}
]
}
}
}
}
提前感谢您。
d3.csv.parse(..)
对其进行处理是最明智的选择。当数据位于同一文件夹中时,无需进行API调用。 - Sumurai8