当前位置: 首页 > news >正文

js中两种异步方式:async+await以及then

第一种方式
在这里插入图片描述
第二种方式
在这里插入图片描述
完整代码
前端代码

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>pywebview example</title>
</head><body><h1>hello pywebview!</h1><p>this is a simple desktop application using pywebview</p><button onclick="GetMessageFromBackground()">Get Message</button><p id="message"></p><script>/*async function GetMessageFromBackground() {const message = await window.pywebview.api.getMessage();document.getElementById("message").innerText = message}*/function GetMessageFromBackground() {window.pywebview.api.getMessage().then(response => {document.getElementById("message").innerText = response});}</script>
</body></html>

后端代码

import webview
import os
import jsonclass API:def getMessage(self):return 'hello from python background'
def main():api=API()webview.create_window('pywebview example','index.html',js_api=api)webview.start()
if __name__=='__main__':main()    

http://www.mrgr.cn/news/30069.html

相关文章:

  • 基于Python的自然语言处理系列(12):使用TorchText和LSTM进行序列到序列(seq2seq)翻译
  • 2024年03月中国电子学会青少年软件编程(图形化)等级考试试卷(一级)答案 + 解析
  • 基于python+django+vue的图书管理系统
  • 【AI视频】Runway文生视频Gen-2、Gen-3详解
  • 【AIGC半月报】AIGC大模型启元:2024.09(下)
  • 【数据结构】排序算法---归并排序
  • Halcon OCR检测 免训练版
  • GEC6818初次连接使用
  • C++(学习)2024.9.18
  • 新手教学系列——非正常关机导致MySQL权限表(db)损坏及修复详解
  • 健康监测功能或暂缓亮相,Apple Watch Series 10最新爆料解析
  • Find My太阳镜|苹果Find My技术与太阳镜结合,智能防丢,全球定位
  • 关于联想笔记本开机无法正常进入到桌面,提示Check Date and Time settings错误的解决方法
  • JavaAPI-String和StringBuffer
  • 【AI大模型】LLM主流开源大模型介绍
  • 网络安全自学笔记
  • iOS17找不到developer mode
  • # 软考 -- 软件设计师 -- 二轮复习(5) -- 面向对象(持续更新)
  • 记软件开发者画图(UML),使用WPS应用制图
  • 【人工智能】如何利用AI高效解决Linux中出现的严重问题?程序员必看小技巧!