导入是否会创建导入库的新副本? [英] Does import create a new copy of imported library?

查看:91
本文介绍了导入是否会创建导入库的新副本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用webpack + vue-loader来创建vuejs应用程序。我有多个组件的 .vue 文件。当我写这样的东西时:

I'm using webpack + vue-loader to create vuejs app. I have multiple .vue files for components. When I write something like this:

import _ from'lodash'

脚本部分 ComponentA.vue ComponentB.vue ,这会创建lodash的两个单独副本还是仅导入引用?

inside the script part of ComponentA.vue and ComponentB.vue, does this create two separate copies of lodash or does it simply import a reference?

推荐答案

导入ES6模块或ES6模块的任何部分生成绑定

Importing an ES6 module, or any part of an ES6 module, produces a binding.


CommonJS模块导出值,而 ES6模块导出不可变绑定。这篇博文解释了这意味着什么。

CommonJS modules export values, while ES6 modules export immutable bindings. This blog post explains what that means.

[来源: ES6模块导出]

所以答案是否定的,它不会创建出口的副本。模块初始化一次,每次导入都会收到对相同值的引用。

So the answer is no, it does not create a copy of the exports. The module is initialised once and each import will receive a reference to the same value.

这篇关于导入是否会创建导入库的新副本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆