[英]How does this import statement work?
I just downloaded a template from a vue cli as 我刚刚从vue cli下载了一个模板
vue init webpack my-project
. vue init webpack my-project
。
and inside Hello.vue I saw an import statement like this. 在Hello.vue内部,我看到了这样的导入语句。
import Hello from '@/components/Hello';
and I am curious what does that @
does. 我很好奇
@
做什么。 It's used at a lot of places but no where it's written what exactly it does. 它在很多地方都使用过,但没有写确切的用途。 Would be great if someone can explain what it does?
如果有人可以解释它的功能,那会很棒吗? and how it is different from a normal import?
它与正常导入有何不同?
If you look in the project at webpack.base.config.js for the webpack template vue-cli creates, you can see there is an alias set: 如果您在webpack.base.config.js的项目中查找vue-cli创建的webpack模板,则可以看到存在一个别名集:
'@': resolve('src')
See: https://github.com/vuejs-templates/webpack/blob/develop/template/build/webpack.base.conf.js 参见: https : //github.com/vuejs-templates/webpack/blob/develop/template/build/webpack.base.conf.js
Line 27. 第27行。
So it's just to make it easier to load modules. 因此,这只是为了更轻松地加载模块。 So you dont need to type things like
import 'component from '../../../src/components'
you can just type ' @/components
'. 因此,您无需键入诸如
import 'component from '../../../src/components'
类import 'component from '../../../src/components'
只需键入' @/components
'。
So it it just for convenience. 只是为了方便。 There is no difference in functionality to a regular import.
功能与常规导入没有区别。
If you are writting the following statement: 如果要编写以下语句:
import Hello from '@/components/Hello'; 从'@ / components / Hello'导入Hello;
In this statement @ means that, it will load the correspondes package and import class,variable and methods into your component. 在此语句中@表示它将加载对应的包并将类,变量和方法导入到您的组件中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.