English | 中文
Optimize the postMessage issue between webview page and vscode extension
Wrapped the official @types/vscode-webview and added some methods.
# pnpm
pnpm add @tomjs/vscode-webview
# yarn
yarn add @tomjs/vscode-webview
# npm
npm add @tomjs/vscode-webview
- API Document provided by jsdocs.io.
- index.d.ts provided by unpkg.com.
Get the persistent state stored for this webview.
Set the persistent state stored for this webview.
Post a message to the owner of the webview
Send message
- type: message type
- message: message content
- options: configuration items
Send and receive messages
- type: message type
- message: message content
- options: configuration items
Listen for messages
- type: message type
- success: listener success callback function
- fail: listener error callback function
Cancel listening for messages
- type: message type
Breaking Updates:
- Export the
WebviewApi
class wrapped by theWebviewApi
of the official @types/vscode-webview- The
postMessage
method is modified to be consistent with the method of the officialWebviewApi
instance - The original
postMessage
andpostAndReceiveMessage
method names are changed topost
andpostAndReceive
- The
- Delete the
WebviewApi
instances:vscodeWebview
andwebviewApi
, which need to be manually imported and instantiated