var web = new WebView() web.show(); web.loadHtml(` <!DOCTYPE html> <html lang="en"> < head > < meta charset = "UTF-8" > < title > WKWebView JS to Swift </ title > < style > body { font - family: -apple - system, BlinkMacSystemFont, sans - serif; padding: 40px; background - color: #f2f2f7; text - align: center; } button { font-size: 18px; padding: 12px 24px; margin: 10px; border: none; border-radius: 8px; background-color: #007aff; color: white; cursor: pointer; } button: hover { background - color: #005fd1; } </ style > </ head > < body > < h1 > Swift 调用演示 </ h1 > < button > 设置值 </ button > < button > 加载脚本 </ button > < script > async function main() { //写入配置参数 setConfig('a', '6666') //获取配置参数 const result = await getConfig("a"); //吐司提示 toast(result.toString()) //运行脚本代码,脚本要写到lamada表达式里 runJS(() => { //脚本写这里 printl("1233") }) //运行脚本文件 runFile("主脚本.js") } </ script > </ body > </ html > `) |