动态添加url会产生语法错误



我在下面的代码中动态传递url,这会产生错误"SyntaxError: Unexpected token ':',因为url是动态添加为https://wizkidtest.daily.co/testcall的,但当我将url编码为'https://wizkidtest.daily.co/testcall'时,它运行良好,在字符串"中添加url会产生差异

let script = this._renderer2.createElement("script");
script.type = `text/javascript`;
script.text = `
{
callFrame = window.DailyIframe.createFrame({
showLeaveButton: true,
iframeStyle: {
position: 'fixed',
width: '100%',
height: '100%'
}
});
callFrame.join({ url: ${this.url} })
}
`;
this._renderer2.appendChild(this._document.body, script);

由于您将整个脚本作为字符串传递,因此需要确保您的url在该脚本中用引号包装,否则它将不会被视为字符串,例如

callFrame.join({ url: "${this.url}" })

callFrame.join({ url: '${this.url}' })

否则,它将创建{ url: https://wizkidtest.daily.co/testcall }的输出,这是错误的。

最新更新