Javascript 未找到导出默认值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45995136/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Export default was not found
提问by Leff
I have a Vue 2 project, and I've written a simple function for translating months in dates, which I would like to import in one of my components, but I'm getting an error:
我有一个 Vue 2 项目,我编写了一个简单的函数来翻译日期中的月份,我想将其导入到我的一个组件中,但出现错误:
export 'default' (imported as 'translateDate') was not found in '@/utils/date-translation'
在“@/utils/date-translation”中找不到导出“默认”(导入为“translateDate”)
The relative file path from the src folder is correct, and I am exporting the function like this:
src 文件夹中的相对文件路径是正确的,我正在导出这样的函数:
export function translateDate(date) {
// my code
}
And then I am importing it in the component like this:
然后我将它导入到组件中,如下所示:
import translateDate from '@/utils/date-translation'
What am I doing wrong?
我究竟做错了什么?
采纳答案by Danil Speransky
You have to specify defaultexplicitly:
您必须default明确指定:
export default function translateDate(date) {
..
}
回答by Alex D
Either specify defaultas mentioned above, or if you're trying to export multiple items from the same file you need to import them with curly brackets.
default如上所述进行指定,或者如果您尝试从同一文件中导出多个项目,则需要使用大括号导入它们。
So you would have:
所以你会有:
export function doWork(){}
export const myVariable = true;
And then you'd import them in a separate file as:
然后你将它们导入到一个单独的文件中:
import { doWork, myVariable} from "./myES6Module"
回答by Farid Vatani
You need to set symlink setting in vue.config.js
您需要在 vue.config.js 中设置符号链接设置
config.resolve.symlinks(false);

