【发布时间】: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*.
...
}
所以我的问题是:“如何访问加载的脚本而不是资源引用?”。
我遵循了here 和here 指南,发现this GitHub issue 似乎正在处理相同的引用问题。但是,对于我的具体情况,解决方案并不明显。
对此的任何帮助将不胜感激!
【问题讨论】:
标签: salesforce lwc