【发布时间】:2020-02-12 18:58:57
【问题描述】:
我在 Nuxt 应用程序的根目录中有一个 constants.js 文件。此文件包含使用module.exports.<var_name> 导出的常量变量。
当这个文件被导入到我的/pages/index.vue中时
import { feature1, feature2, feature3, news } from '../constants';
它抛出如下错误:
TypeError: Cannot set property 'feature1' of undefined
at Module.eval (constants.js?c4f5:1)
at eval (constants.js:111)
at Module../constants.js (pages_index.js:283)
at __webpack_require__ (runtime.js:796)
constants.js :-
module.exports.feature1 = [...];
module.exports.feature2 = [...];
...
index.vue:-
import { feature1, feature2, feature3, news } from '../constants';
export default {
data() {
return {
newsList: news,
isMobile: false,
featuresList1: feature1,
featuresList2: feature2,
featuresList3: feature3,
showAll: false
};
}
}
注意 - 一旦您构建并部署到生产环境,此错误就不会出现。很奇怪。
打我的头。请帮忙!
【问题讨论】:
标签: nuxt.js