简体   繁体   English

Sharepoint Online SPFX Web部件React-如何基于环境动态选择脚本?

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

I want to dynamically choose which script to use in my web part. 我想动态选择要在Web部件中使用的脚本。

My imports are as follows: 我的进口如下:

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

And I want to do this in my component: 我想在我的组件中执行此操作:

//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');
} ;

Is this possible? 这可能吗?

I think you can make use of require method somewhat as below: 我认为您可以使用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.

相关问题 如何使用来自共享点在线 SPFx webpart 的 azure 认知搜索 - how to use azure cognitive search from a sharepoint online SPFx webpart SharePoint Framework SPFx和React - SharePoint Framework SPFx & React 如何保护您的 spfx 设计 SharePoint 在线表格和工作流程 - spfx 项目的最佳安全性 - How to secure your spfx designed SharePoint Online form and workflow - the best security for an spfx project 如何使用 React Spfx 检查 SP Online 中哪个页面是 aspx 主页 - How to check which page is the aspx homepage in SP Online with React Spfx 如何生成作者链接 - Spfx/React 和 Sharepoint 2019? - How to generate Link to Author - Spfx/React and Sharepoint 2019? 对SharePoint Framework SPFx的React Dropzone - React Dropzone for SharePoint Framework SPFx Sharepoint 自定义列表的 SPFx React FileViewer - SPFx React FileViewer for Sharepoint Custom List 使用 React & PnPJS 更新 SharePoint spfx 中的数组 - Updating an array in SharePoint spfx using React & PnPJS 如何在线在 Sharepoint 中托管示例 React 应用程序? - How to host a sample React Application in Sharepoint online? SPFx | 客户端 Web 部件 | 反应 | 如何通过部分组件传递 sharepoint 上下文 - SPFx | Client WebPart | React | How to pass sharepoint context through partial components
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM