我正在制作一个nuxt.js项目和获取错误:
在浏览器中,我看到以下错误:
__webpack_require__(...).context is not a function
在终端,我得到了这个错误:
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
这是我的密码
<script>
export default {
name: 'SectionOurClients',
data() {
return {
imageDir: '../assets/images/clients/',
images: {},
};
},
mounted() {
this.importAll(require.context(this.imageDir, true, /\.png$/));
},
methods: {
importAll(r) {
console.log(r)
},
},
};
</script>
我已经使用了上面HERE页的脚本.
请帮忙,谢谢.
EDIT:下面是@MaxSinev的答案,下面是我的工作代码:
<template lang="pug">
.row
.col(v-for="client in images")
img(:src="client.pathLong")
</template>
<script>
export default {
name: 'SectionOurClients',
data() {
return {
images: [],
};
},
mounted() {
this.importAll(require.context('../assets/images/clients/', true, /\.png$/));
},
methods: {
importAll(r) {
r.keys().forEach(key => (this.images.push({ pathLong: r(key), pathShort: key })));
},
},
};
</script>