【问题标题】:How to access loaded script in Salesforce Lightning Web Component?如何访问 Salesforce Lightning Web 组件中加载的脚本?
【发布时间】:2021-07-21 11:49:07
【问题描述】:

loading an external library 在 Lightning Web 组件中时,我似乎无法访问实际脚本。 相反,我只能通过检查解析的导入字符串来找到对静态资源的引用。

phone.js:

import { LightningElement } from 'lwc';
import { loadScript } from 'lightning/platformResourceLoader';
import JsSIP from '@salesforce/resourceUrl/jssip';
// import * as JsSIP from 'jssip';

export default class Phone extends LightningElement 
{
    ...
    async connectedCallback() {
        console.log(JsSIP); // This resolves to the static resource location inside the connected org in a string.

        loadScript(this, JsSIP + '/jssip.js')
            .then(() => { 
                console.log(JsSIP.version); // This is only accessing the resource reference, not the actual script; so result is *undefined*. 
    ...
}

所以我的问题是:“如何访问加载的脚本而不是资源引用?”。

我遵循了herehere 指南,发现this GitHub issue 似乎正在处理相同的引用问题。但是,对于我的具体情况,解决方案并不明显。

对此的任何帮助将不胜感激!

【问题讨论】:

    标签: salesforce lwc


    【解决方案1】:

    我认为您的库在完成加载后会创建一个名为 JsSIP 的“全局”对象。并且名称与文件引用的名称冲突。你能把它命名为import jssipjsSipLibrary 之类的,看看会发生什么?

    debugger; 语句放入then 并在设置-> 调试模式中启用调试。使用浏览器的控制台打开页面(大多数时候是 F12)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-11
      • 1970-01-01
      • 2019-09-08
      • 2019-10-02
      • 2022-01-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多