1. 程式人生 > >ES 6 import/export

ES 6 import/export

AS IT ret ntb end err .get ase roo

import React, { Component } from ‘react‘;

import ReactDOM from ‘react-dom‘;
import { BrowserRouter, Switch, Route } from ‘react-router-dom‘;

import userInfo from ‘./environment‘;//一定要在所有引入的頁面的最前面進行引入

import DietPage from ‘./diet/DietPage‘;
import AddDietPagePage from ‘./diet/AddDietPage‘;
import SubmitDietPage from "./diet/SubmitDietPage";

import DietDetail from ‘./diet/DietDetail‘;

import ‘./index.css‘;

//
console.log(userInfo);

const Main = () => {
    debugger
    console.log(userInfo)
    return(
        <Switch>
            <Route exact path=‘/wechat‘ component={DietPage}/>
            <Route path=‘/add‘ component={AddDietPagePage}/>
            <Route path=‘/submit‘ component={SubmitDietPage}/>
            <Route path=‘/detail/:id‘ component={DietDetail}/>
        </Switch>
    )
}

//<BrowserRouter basename="/minooo" />假如你需要把頁面部署到服務器的二級目錄,你可以使用 basename 設置到此目錄。
ReactDOM.render( <BrowserRouter><Main /></BrowserRouter>, document.getElementById(‘root‘));

  

每次import,都會把import的頁面加載完才執行下面的。
因此,變量的定義一定要在最前面做,比如要是在當前頁面定義的變量,在其他頁面export,其他的頁面就無法讀取到。


ES 6 import/export