Home  >  Q&A  >  body text

javascript - ES6 import 导出规则

最近在看redux, git clone https://github.com/reactjs/redux.git自己在实践过程中,发现一个问题就是 import 导入的时候,没有完整的导入路径,也能生效,import counter from './reducers' import counter from './reducers'/index, 这里的index为什么可以省略?没有配置什么规则,webpack里面配置规则也只是允许扩展后缀为.js?不是很懂!

import React from 'react'
import ReactDOM from 'react-dom'
import { createStore } from 'redux'
import Counter from './components/Counter'
import counter from './reducers'

const store = createStore(counter);
const rootEl = document.getElementById('root');

const render = () => ReactDOM.render(
        <Counter 
            value={store.getState()}
            onIncrement={() => store.dispatch({type: 'INCREMENT'})}
            onDecrement={() => store.dispatch({type: 'DECREMENT'})}
        />,
        rootEl
    );
render();
store.subscribe(render);
伊谢尔伦伊谢尔伦2723 days ago493

reply all(2)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-04-11 10:06:25

    ECMAScript 6 入门 - Module

    在第 11 部分 跨模块常量,有提到过 index.js 问题,默认加载就是 index.js,

    仔细阅读,你会对 import 了解到,这个教程写的真好!

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-11 10:06:25

    index.js是默认的,不用写。

    reply
    0
  • Cancelreply