我正在使用JSPM,我也是ES6的新手
我想知道在ES6中有条件的时候进口的正确方法是什么
方式-1:
// should load only module required
import $ from 'jquery';
import 'bootstrap';
if(!$.core.login){
System.import('lib/log-in');
}else{
System.import('lib/logged-in');
}
方式-2:
//load both at once and consume which ever is valid
import $ from 'jquery';
import 'bootstrap';
import {loginPlz} from 'lib/log-in';
import {alreadyIn} from 'lib/logged-in';
if(!$.core.login){
loginPlz();
}else{
alreadyIn();
}
答案 0 :(得分:1)
我会说(每this)
import $ from 'jquery';
import 'bootstrap';
if(!$.core.login){
import('./lib/log-in').then(loginPlz => loginPlz());
}else{
import('./lib/logged-in').then(alreadyIn => alreadyIn());
}