最近作一个项目,写nodejs,又写vue,而后就有点混乱了。
当时想引入一个config文件,而后很天然的啪啪啪的敲了下面几行代码vue
//错误代码 export default const config = { static_img_url: 'http://localhost:7001/images/' }
啪啦啪啦,查了一下,说缘由是export default中的default是一种特殊的系统变量,export default的含义是把此命令后面的变量赋值给default这个特殊的系统变量,并把它导出到其余模块中使用。如此一来,export default const...或者export default var...等语句就是很是明显的错误了。node
好,改了一下以下:浏览器
//仍是错误代码 const config = { static_img_url: 'http://localhost:7001/images/' } export default config
仍是报错:函数
为何呢???发现掉坑了,搞混乱了。正确应该以下:url
//正确代码 const config = { static_img_url: 'http://localhost:7001/images/' } module.exports = config
其实就是Node和浏览器端所支持的模块规范不一样。spa
参考引用:引用.net