簡體   English   中英

Sharepoint Online SPFX Web部件React-如何基於環境動態選擇腳本?

[英]Sharepoint Online SPFX Web parts React - How to dynamically choose script based on enviro?

我想動態選擇要在Web部件中使用的腳本。

我的進口如下:

import * as jQuery from 'jquery';
import 'jqueryui';

我想在我的組件中執行此操作:

//Select script to us 
//if (Environment.type === EnvironmentType.Local) {
  //import * as jQuery from 'jquery';
  //import 'jqueryui';
//} else if (){
   SPComponentLoader.loadCs('//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css');
  SPComponentLoader.loadScript('//code.jquery.com/jquery-min.1.12.1.js');
} ;

這可能嗎?

我認為您可以使用require方法,如下所示:

//Select script to use 
if (Environment.type === EnvironmentType.Local) {
    require('jQuery');
    require('jqueryui');  
} else if (){
   SPComponentLoader.loadCss('//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css');
   SPComponentLoader.loadScript('//code.jquery.com/jquery-min.1.12.1.js');
};

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM