2.0.2 • Published 8 months ago

@tomjs/vscode-webview v2.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
8 months ago

@tomjs/vscode-webview

npm node-current (scoped) NPM jsDocs.io

English | 中文

优化 webview 页面与 vscode 扩展的 postMessage 问题

对官方的 @types/vscode-webview 进行了封装并增加了一些方法。

安装

# pnpm
pnpm add @tomjs/vscode-webview

# yarn
yarn add @tomjs/vscode-webview

# npm
npm add @tomjs/vscode-webview

文档

使用

WebviewApi

getState(): any

获取此 webview 存储的持久状态。

setState(state: any): any

设置此 webview 存储的持久状态。

postMessage(message:any)

向 WebView 的所有者发布消息

post(type, message, options)

发送消息

  • type: 消息类型
  • message: 消息内容
  • options: 配置项

postAndReceive(type, message, options): Promise

发送并接收消息

  • type: 消息类型
  • message: 消息内容
  • options: 配置项

on(type, success, fail)

监听消息

  • type: 消息类型
  • success: 监听成功回调函数
  • fail: 监听失败回调函数

off(type)

取消监听消息

  • type: 消息类型

重要说明

v2.0.0

破坏性更新:

  • 导出由官方 @types/vscode-webviewWebviewApi 来封装的 WebviewApi
    • postMessage 方法修改为与官方的 WebviewApi 实例的方法一致
    • postMessagepostAndReceiveMessage 方法名改为 postpostAndReceive
  • 删除 WebviewApi 的实例:vscodeWebviewwebviewApi,需要手动引入并实例化
2.0.2

8 months ago

1.1.0

10 months ago

2.0.1

9 months ago

2.0.0

9 months ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago