简体   繁体   English

从 '.' 导入 {} 是什么意思做?

[英]What does import {} from '.' do?

I was looking at some source code of a library and I saw this import我正在查看一个库的一些源代码,我看到了这个导入

import {SheetsRegistry, JssProvider, withStyles} from '.'

What does this do?这是做什么的? How does it import from '.'它如何from '.'导入?

The code you shared imports those declarations from index.js in the same directory.您共享的代码从同一目录中的index.js导入这些声明。

index.js:索引.js:

// @flow
import withStyles from './withStyles'

export {ThemeProvider, withTheme, createTheming, useTheme} from 'theming'
export {default as createUseStyles} from './createUseStyles'
export {default as JssProvider} from './JssProvider'
export {default as jss} from './jss'
export {SheetsRegistry, createGenerateId} from 'jss'
export {default as JssContext} from './JssContext'
export {default as styled} from './styled'
export {default as jsx, create as createJsx} from './jsx'
export {withStyles}

// Kept for backwards compatibility.
export default withStyles

In this example, index.js is being used to re-export some of the declarations within the src directory.在此示例中, index.js用于重新导出src目录中的一些声明。 This pattern makes it easier to move the declarations around without having to rewrite many imports.这种模式使移动声明变得更容易,而不必重写许多导入。

******The difference between named exports and default exports.****** ******命名导出和默认导出的区别。******

1-named exports 1-命名出口

export function, constant, variable...etc in Constant.js Constant.js中的导出函数、常量、变量...等

export const CREATE = 'CREATE';
export const DELETE = 'DELETE';

import like this in index.jsindex.js中这样导入

import {CREATE,DELETE} from './Constants';

2-default exports 2-默认导出

export it in Constant.jsConstant.js中导出

const update = ()=> 'UPDATE'
export default update();

and import like this in index.js并在 index.js 中像这样导入

import UPDATE from './Constants';

多种类型

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 '@' 有什么作用?... 从 '@ModuleName' 导入 {ModuleName} - What does '@' do?… import {ModuleName} from '@ModuleName' Javascript 中的 import * 有什么作用? - What does import * do in Javascript? ':' 冒号在 JavaScript 的导入中有什么作用? - What does ':' colon do in JavaScript's import? 进口*作为“…”中的东西是什么类型的? - What type does `import * as Thing from '…'` make? SASS / SCSS @import前面的〜是什么意思? - What does the ~ in front of the SASS/SCSS @import mean/do? 当未定义默认导出时,从“模块”中导入模块的导入是什么?为什么它与作为模块导入*不同? - What does import Module from 'module' import when no default export is defined and why is it different from import * as Module? 导入的双重**是什么? - What double ** do in an import? React:以下是什么意思:从'./registerReducer'中导入*,如fromRegister? - React: What does following mean: import register, * as fromRegister from './registerReducer'? ES6:“从'jquery'中导入$”真的意味着什么? - ES6: What does “import $ from 'jquery'” really means? 在Javascript中执行“从someModule导入someModuleName”时会发生什么 - What happens when you do “import someModuleName from someModule” in Javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM