React Native import 檔案的小技巧

weixin_34050427發表於2017-01-10

開發中經常需要 import 其他 js 檔案,如果需要同時匯入一些相關的 js 檔案時,可以建立一個索引檔案方便引用。

第一步:建立index.js

在 index.js 中 import 相關的 js 檔案

'use strict';

import * as Type from './network/EnvironmentConst';
import Request from './network/RequestManager';
import AppContext from './network/AppContext';
import ApiServiceFactory from './network/ApiServiceFactory';

module.exports = {
    ApiServiceFactory,
    Type,
    Request,
    AppContext
};

第二步:使用

如果需要使用這些類,只需要匯入index檔案就可以了~

import {Request, ApiServiceFactory, AppContext, Type} from '../expand/index';

相關文章