【发布时间】:2019-05-31 03:04:51
【问题描述】:
我从 vue 和 nuxt 开始,我有一个使用 vuetify 的项目,我正在尝试修改轮播组件以从静态文件夹动态加载图像。到目前为止,我想出了:
<template>
<v-carousel>
<v-carousel-item v-for="(item,i) in items" :key="i" :src="item.src"></v-carousel-item>
</v-carousel>
</template>
<script>
function getImagePaths() {
var glob = require("glob");
var options = {
cwd: "./static"
};
var fileNames = glob.sync("*", options);
var items = [];
fileNames.forEach(fileName =>
items.push({
'src': '/'+fileName
})
);
return items;
}
export default {
data() {
return {items :getImagePaths()};
}
};
</script>
当我测试这个时,我看到:
ERROR in ./node_modules/fs.realpath/index.js
Module not found: Error: Can't resolve 'fs' in '....\node_modules\fs.realpath'
ERROR in ./node_modules/fs.realpath/old.js
Module not found: Error: Can't resolve 'fs' in ....\node_modules\fs.realpath'
ERROR in ./node_modules/glob/glob.js
Module not found: Error: Can't resolve 'fs' in '....\node_modules\glob'
ERROR in ./node_modules/glob/sync.js
Module not found: Error: Can't resolve 'fs' in '.....\node_modules\glob'
在谷歌上搜索我看到一堆引用,例如https://github.com/webpack-contrib/css-loader/issues/447。
这些建议您必须使用以下内容对 webpack 配置文件进行 midify:
node: {
fs: 'empty'
}
我对 webpack 知之甚少。我找到了 https://nuxtjs.org/faq/extend-webpack/ ,但不确定在这种情况下如何修改 webpack 配置文件。
我该怎么做?
【问题讨论】:
-
你不能在客户端使用 fs 模块
-
好的,你有什么建议。
-
创建一个 api 端点,该端点将返回图像的图像 url 并进行 api 调用以将其放入 asyncData
-
这个需要axios模块吗?
-
没必要,但是可以
标签: node.js vue.js webpack nuxt.js