简体   繁体   English

无法将 Static 资源(JS 文件)加载到 Salesforce 中的 LWC 组件

[英]Unable to load Static resource (JS file) to LWC component in Salesforce

I tried using the code below, but was not able to get the JavaScript file from the static resource (Feedback.js) and this file is not in ZIP folder.我尝试使用下面的代码,但无法从 static 资源 (Feedback.js) 中获取 JavaScript 文件,并且该文件不在 ZIP 文件夹中。

loadCurrencyJS() {

    window.loadingCurrencyjs = true;
    let path = "/resource/Feedback";
    loadScript(this, path).then((res)=>{
        console.log("Currencyjs loaded");
        window.loadingCurrencyjs = false;
        window.CurrencyjsLoaded = true;
    }).catch(e=>{
        console.log("File not loaded");
        window.CurrencyjsLoaded = false;
    })
  }  

I also tried with below code:我还尝试了以下代码:

import Qualtrics_Feedback from '@salesforce/resourceUrl/Qualtrics_Feedback';
Promise.all([
            loadScript(this, Qualtrics_Feedback)
        ]).then(() => {
            window.console.log("Load");
        }).catch(error => {
            window.console.log("Error: "+error);
            });

I think here is the documentation you're looking for:我认为这是您要查找的文档:

For js code I would recommend to use first method unless you're trying to import a library.对于 js 代码,除非您尝试导入库,否则我建议使用第一种方法。 Please note that library doing DOM manipulation will probably not work because of Lightning Locker .请注意,由于Lightning Locker ,进行 DOM 操作的库可能无法工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM